L
Lonifasiko
Hi,
I'm having quite a strange behaviour when using Generics classes and
ComboBox controls in Winforms applications. Hope somebody has seen the
same behaviour.
Two combobox controls in my form. I want to load them with same data.
I've got a generics list full of drinks (List<Drink>).
If I for example do:
combo1.DataSource = myList; // myList is a List<Drink> estructure
combo1.DisplayMember = "description";
combo1.ValueMember = "code";
combo2.DataSource = myList;
combo1.DisplayMember = "description";
combo1.ValueMember = "code";
No problems, combos are loaded in the correct way. Then I select a
value in first combo. Selected value properly selected. When I select
a value in the second combo, same value gets selected in first combo.
It seems like they would be cloned combos that behave the same way. In
fact, when one item is selected, SelectedIndexChanged method is fired
for both of the combos.
My workaround has been to load items in the combo with a foreach
instruction iterating the list of drinks:
foreach (Drink d in myList)
combo1.Items.Add(d);
Just to let the group know...
I'm having quite a strange behaviour when using Generics classes and
ComboBox controls in Winforms applications. Hope somebody has seen the
same behaviour.
Two combobox controls in my form. I want to load them with same data.
I've got a generics list full of drinks (List<Drink>).
If I for example do:
combo1.DataSource = myList; // myList is a List<Drink> estructure
combo1.DisplayMember = "description";
combo1.ValueMember = "code";
combo2.DataSource = myList;
combo1.DisplayMember = "description";
combo1.ValueMember = "code";
No problems, combos are loaded in the correct way. Then I select a
value in first combo. Selected value properly selected. When I select
a value in the second combo, same value gets selected in first combo.
It seems like they would be cloned combos that behave the same way. In
fact, when one item is selected, SelectedIndexChanged method is fired
for both of the combos.
My workaround has been to load items in the combo with a foreach
instruction iterating the list of drinks:
foreach (Drink d in myList)
combo1.Items.Add(d);
Just to let the group know...