I’m populating my combobox with an underlying value and a display value this way:
Dictionary<int, string> Platypi = duckBillData.GetPlatypiVals();
comboBoxPlatypus.DataSource = new BindingSource(Platypi, null);
comboBoxPlatypus.ValueMember = "Key";
comboBoxPlatypus.DisplayMember = "Value";
Now I want to extract the ValueMember of the selected item. How do I do that? None of the “obvious” things seem to have a “ValueMember”…I’ve tried:
int id = comboBoxPlatypus.ValueMember;
int id = comboBoxPlatypus.SelectedIndex. <-- no "ValueMember" here...
int id = comboBoxPlatypus.SelectedItem. <-- no "ValueMember" here...
ValueMembertells the combo box which property of your original collection to bind to, it is not the bound object itself.SelectedItemshould contain your resulting value. You just need to cast it to the correct type, which in this case is yourintkey.