如何两个组合框所选的项目与一个单一的数据源中分离?组合、数据源、所选、两个

2023-09-04 22:51:34 作者:年少泪愿偿

在一个形式,我有两个组合框至极具有相同的数据源(它们的元素列表是相同的)。当用户在控制中的一个选择一个项目,其他控件的选择项也被修改。这不是我想要的。

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.

我怎么能这样做?

推荐答案

或者你可以使用...

Or you could use...

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