In other words, there is no longer any need for a Tag property on each item.
The Tag is traditionally used to hold additonal relevant data for an
item. However, since the .NET list controls all hold a collection of
"objects", and not just "strings", each item can already hold all the
data it needs.
Think of it this way... if you just want to hold strings, with some
associated random data, create a class like this:
class ComboBoxItem {
string _Contents;
public string Contents {
get { return _Contents; }
set { _Contents = value; }
}
object _Tag;
public object Tag {
get { return _Tag; }
set {_Tag = value; }
}
public ComboBoxItem(string contents, object tag)
{
this._Contents = contents;
this._Tag = tag;
}
public override string ToString(){ return _Contents; }
}
Then, when you want to add your strings to the comboxbox, instead of
adding them directly like this:
comboBox1.Items.Add("My first item");
Do it like this:
// the second parameter can be anything you want,
// here I'm using the integer '1' as my tag data
comboBox1.Items.Add(new ComboBoxItem("My First item", 1));
If you already have a custom class, you don't need the ComboBoxItem
class - just make sure its ToString() method returns the string you want
to appear in the combobox, as Stoicho alluded to.
Hope that helps.
Joshua Flanagan
http://flimflan.com/blog