I'm creating a combobox programmatically like this:
var cbo = new ComboBox {
DataSource = mylist,
SelectedIndex = mylist.IndexOf(myvalue)
};
I'm not setting ValueMember
so that the value will be the object itself. When I do the above I get the following exception on the SelectionIndex
line:
InvalidArgument=Value of '3' is not valid for 'SelectedIndex'. Parameter name: SelectedIndex
Is it because the combobox is still being created and therefore the DataSource
is still not populated? If yes, what's the correct way to set the index?