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 ite开发者_StackOverflow社区m 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?
Or you could use...
var dataSource = new[] { "item1", "item2", "item3" };
comboBox1.DataSource = dataSource;
comboBox2.BindingContext = new BindingContext();
comboBox2.DataSource = dataSource;
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();
精彩评论