Dictionary To Fill A Combobox

post_id: 26 / post_date: 2009-10-13



Simplest was to have key / value pairs displayed in a ComboBox.

comboBox1.DisplayMember = "Value";
comboBox1.ValueMember = "Key";
Dictionary names = new Dictionary();
names.Add("1", "one");
names.Add("2", "two");
comboBox1.DataSource = names.ToArray();

//and then in the:
comboBox1_SelectedValueChanged
//you can listen to the
comboBox1.SelectedValue / comboBox1.Text