I usually use a helper class that overrides the ToString() method. Any class
that overrides the ToString() method with a "useful" string will work.
public class ComboBoxItem
{
private string display;
private object data;
public ComboBoxItem(string display, object data)
{
this.display = display;
this.data = data;
}
public override string ToString()
{
return display;
}
}
You'd add it to your ComboBox like this:
comboBox.Items.Add(new ComboBoxItem("asdf", yourObjectHere));
"Kannan" <an*******@discussions.microsoft.com> wrote in message
news:7F**********************************@microsof t.com...
hi,
thanks for your quick response.
But my question is related to design time.
Is it possible can we do it in design time without using datasource
property. In VB, I have used Item data and value data property. similarly what is
available in C# combo box (without using datasource property)? please let me know.
thanks,
Kannan
----- gary hitch wrote: -----
it's very easy - ex :
ComboBox cb = new ComboBox();
string s = "hi";
cb.Items.Add( s );
// or
cb.Items.AddRange( anObjectArray );
where anObjectArray is an array of System.Object based objects such
as strings etc.
;-)
"Kannan" <an*******@discussions.microsoft.com> wrote in message
news:C2**********************************@microsof t.com... > hi,
> Currently I am working in C# windows application. I am trying to
fill combo box with values. > We have to always use datasource property for filling values in
Combo box?? > In VB, normally i have used Item data property and display data
property. > We can't use this similar method in C#?? please let me know. >> thankjs,
> Kannan