开发者

How to separate the selected item of two combobox with a single DataSource?

开发者 https://www.devze.com 2022-12-11 14:17 出处:网络
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开发者_StackOverfl

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消