Binding Combobox Using Dictionary as the Datasource

SortedDictionary<string, int> userCache = new SortedDictionary<string, int>
{
  {"a", 1},
  {"b", 2},
  {"c", 3}
};
comboBox1.DataSource = new BindingSource(userCache, null);
comboBox1.DisplayMember = "Key";
comboBox1.ValueMember = "Value";

But why are you setting the ValueMember to “Value”, shouldn’t it be bound to “Key” (and DisplayMember to “Value” as well)?

Leave a Comment