Posted By

indra on 10/19/10


Tagged

binding


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Tyster
cybermax


Bind a ComboBox to a generic Dictionary


 / Published in: C#
 

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

  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?

Report this snippet  

You need to login to post a comment.