All the items in a combo box are of type Object. Which means that you can insert objects of any type in there because all objects in C# inherit from Object.
So if you have a need to store more info in a combo box item that what the control will allow, all you do is create a new class (call it "ComboItemEx") that has public properties for the info you want to store. You would also override the ToString method to return the text you want displayed (the .NET Combo control calls ToString to show the values to the user).
Code:
public class ComboItemEx
{
private String m_name;
private int m_value;
public ComboItemEx(String name, int value)
{
m_name = name;
m_value = value;
}
' add your properties here
' Name, Value
public override String ToString()
{
return m_name;
}
}
And then when you load up the combo with your items, you would use instances of your new class instead of what you had been doing.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.