带Key,Value实现的Combobox
struct itemEx
{
public object Value;
public string Text;
public itemEx(object value, string text)
{
this.Value = value;
this.Text = text;
}
//重点是override ToString
public override string ToString()
{ return Text; }
}
{
public object Value;
public string Text;
public itemEx(object value, string text)
{
this.Value = value;
this.Text = text;
}
//重点是override ToString
public override string ToString()
{ return Text; }
}
ComboBoxItemCollection coll = comboBoxEdit1.Properties.Items;
coll.BeginUpdate();
try
{
coll.Add(new itemEx("Sven", "Petersen"));
coll.Add(new itemEx("Cheryl", "Saylor"));
coll.Add(new itemEx("Dirk", "Luchte"));
}
finally
{
coll.EndUpdate();
comboBoxEdit1.SelectedIndex = -1;
}
coll.BeginUpdate();
try
{
coll.Add(new itemEx("Sven", "Petersen"));
coll.Add(new itemEx("Cheryl", "Saylor"));
coll.Add(new itemEx("Dirk", "Luchte"));
}
finally
{
coll.EndUpdate();
comboBoxEdit1.SelectedIndex = -1;
}
private void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e)
{
itemEx item = new itemEx();
item = (itemEx)(this.comboBoxEdit1.SelectedItem);
string strValue = item.Value.ToString().Trim();
}
{
itemEx item = new itemEx();
item = (itemEx)(this.comboBoxEdit1.SelectedItem);
string strValue = item.Value.ToString().Trim();
}