views:

77

answers:

2

On a form, I have two combobox wich have the same DataSource (their elements list are the same). When the user select an item in one of the control, the other control's selected item is also modified. That's not what I want.

I'd like to have both list populated with the same DataSource (as I currently do), but I'd like their selected items to be independent from each other.

How can I do that?

+1  A: 

You need to create two different instances of the data source. For this you may use the ToArray extension method:

var dataSource = new string[] { "item1", "item2", "item3" };
comboBox1.DataSource = dataSource.ToArray();
comboBox2.DataSource = dataSource.ToArray();
Darin Dimitrov
+3  A: 

Or you could use...

var dataSource = new[] { "item1", "item2", "item3" };
comboBox1.DataSource = dataSource;
comboBox2.BindingContext = new BindingContext();
comboBox2.DataSource = dataSource;
Peter Rennie