Code Snippet
public
struct MyStruct
{
int x;
string name;
public int ID
{
get { return x; }
}
public string Name
{
get { return name; }
}
public MyStruct(int x, string n)
{
this.x = x;
name = n;
}
}
private void toolStripComboBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
toolStripComboBox1.ComboBox.SelectedIndex = -1;
//Same goes for comboBox1.ComboBox.SelectedItem = null;
e.SuppressKeyPress = true;
}
}
private void Form1_Load(object sender, EventArgs e)
{
MyStruct[] ms = { new MyStruct(1, "one"), new MyStruct(2, "two"), new MyStruct(3, "three") };
DataTable t = new DataTable();
t.Columns.Add("ID", typeof(int));
t.Columns.Add("Name", typeof(string));
foreach (MyStruct s in ms)
{
DataRow r = t.NewRow();
r[0] = s.ID;
r[1] = s.Name;
t.Rows.Add(r);
}
toolStripComboBox1.ComboBox.DisplayMember = "Name";
toolStripComboBox1.ComboBox.ValueMember = "ID";
toolStripComboBox1.ComboBox.DataSource = t;
}