Class的定义
public class ComboBoxItem
{
private string _text=null;
private object _value=null;
public string Text
{
get{return this._text;}
set{this._text=value;}
}
public object Value
{
get {return this._value;}
set{this._value=value;}
}
public override string ToString()
{
return this._text;
}
}
赋值:
ComboBoxItem newItem = new ComboBoxItem();
newItem.Text = "abc"+i.ToString();
newItem.Value = "value"+i.ToString();
comboBox1.Items.Add(newItem);
取值:
ComboBoxItem myItem = (ComboBoxItem)comboBox1.Items[0];
string strValue = myItem.Value.ToString();
MessageBox.Show(strValue);