Binding a ComboBox to an IList and Using SelectedValue

I have ComboBox, as shown below, where KVPListis IList(from KeyValuePair, if that matters):

comboBox.DisplayMember = "Value";
comboBox.ValueMember = "Key";
comboBox.DataSource = KVPList;

Then I set the binding to SelectedValue, binding to BindingSource(to DataSet). For some reason, the combo box is always blank when the form is displayed. However, it is filled in correctly (the values ​​are IListdisplayed perfectly and can be selected).

Now I tried my best to trace, and it seems to initially correctly set the SelectedValue value to the binding, but then somewhere along the way it gets from reset to null. I played with things that evoke, but to no avail.

Can someone shed some light on this or suggest a workaround?

For recording in the same form, I have another ComboBoxin the same form, while still SelectedValueattached to the same BindingSource. DataSourceis DataSet, not IList, and it works like a charm. You may be able to make DataTablefrom IList, but this seems like a lot of extra overhead; I generate IListfrom the listing.

+5
source share
1 answer

Uch. After half a day spent on it, I realized this. It was a complete mistake on my part.

KVPList IList KeyValuePair< short ,string>, int. , databinding SelectedValue. DisplayMember ValueMember, SelectedValue. ValueMember short, int, , , null.

- , , , .

, - . , , , , null. , short int , , (int)10 == (short)10, true.

+7

All Articles