Bind a ComboBox to a generic Dictionary


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. var choices = new Dictionary<string, string>();
  2. choices["A"] = "Arthur";
  3. choices["F"] = "Ford";
  4. choices["T"] = "Trillian";
  5. choices["Z"] = "Zaphod";
  6. comboBox1.DataSource = new BindingSource(choices, null);
  7. comboBox1.DisplayMember = "Value";
  8. comboBox1.ValueMember = "Key";
  9.  
  10. //Now you can set comboBox1.SelectedValue = "F" and it will display "Ford"! How cool is that?

URL: http://madprops.org/blog/Bind-a-ComboBox-to-a-generic-Dictionary/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.