I know this question comes up a lot, but I have only found workarounds and no answer.
I have a databound ComboBox that is bound to a class. The class is the wrapper for a lookup table (lets call them cLookups and cLookup).
The initialisation code looks a little like the following:
cbo.DisplayMember = "Description"
cbo.ValueMember = "ID"
cbo.DataSource = theLookups
I then want to set the currently selected item in the combobox to an ID in the lookup. So:
cbo.SelectedValue = "X"
This returns "Object reference not set to an instance of an object" as SelectedValue seems to be expecting an Object of type cLookup.
I could create a cLookup object and pass to SelectedItem, but this seems a little OTT.
I don't want to use a Find function on the combobox as this would mean having to know the description.
MS help states that as long as the type is the same as the type of ValueMember then it should work; these are both Strings.