Click here to Skip to main content
15,908,264 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I found an interesting issue during my work. I am setting different SelectedIndex values to two ComboBoxes in my Form. But both the ComboBoxes have the same value which is set at the end.
Why this might be so?
My code is like this:
C#
var list = new List<system.collections.dictionaryentry>();
list.Add(new System.Collections.DictionaryEntry("one", 1));
list.Add(new System.Collections.DictionaryEntry("two", 2));

comboBox1.DataSource = list;
comboBox1.DisplayMember = "Key";
comboBox1.ValueMember = "Value";
comboBox1.SelectedIndex = 0;

comboBox2.DataSource = list;
comboBox2.DisplayMember = "Key";
comboBox2.ValueMember = "Value";
comboBox2.SelectedIndex = 1;

Here at the end of the function, both comboBox1 and comboBox2 have SelectedIndex value as 1 instead of being 0 and 1 respectively.
Any idea? :)
regards
Fadi
Posted
Updated 10-Aug-10 4:06am
v2
Comments
koool.kabeer 10-Aug-10 10:19am    
that may be because we are using the same DataSource of two ComboBox...
may be the SelectedIndex is Bounded to the Currect Item in the DataSource...
i hope any one have an idea on this....

1 solution

Is there anything in ComboBox2.SelectedIndexChanged Event?
 
Share this answer
 
Comments
koool.kabeer 10-Aug-10 10:00am    
i too have tested that...
the same with me...
nothing there in ComboxBox2.SelectedIndexChanged Event Handler
koool.kabeer 10-Aug-10 10:10am    
even when i am changing the index of one ComboBox the index of another
ComboBox is also getting changed... with the same index..
Goutam Patra 11-Aug-10 1:30am    
OK, I overlooked the situation. Its because you are using the same list for the both combobox.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900