The problem is strange, I have a combobox which is correctly filled with items through the DataSource properties (it binds to a bindingSource item, which contains a displaymember and a valuemember), this is a simple combobox which allows me to select suppliers by choosing between their names and not their ids. The problem is that when I change SelectedValue because I want an option set as the default one, I discovered that the List property is empty (I inherited the combobox class in another one), However when the combobox is shown, I have items inside it, so maybe the problem is related to WHEN data is really loaded from the datasource (maybe it's loaded only after displaying it?). When should I change my SelectedValue so?There isn't any "Shown" event in the control
Thanks for any suggestions
Update 1: I tested in your way but it's not this the case (the key is a long but even if I cast it it's not working), in fact the interesting thing is that I have a setter that allows me to set SelectedValue, even if doesn't throw exceptions, in the next MessageBox the Items.Count give me 0 as value, which is very strange, because when the combobox is shown on the form it has all values i wanted. Here is the code for my setter:
public object InputValue
{
get
{
return SelectedValue;
}
set
{
SelectedValue = ((long)value);
MessageBox.Show(this.Items.Count.ToString());
}
}