如何两个组合框所选的项目与一个单一的数据源中分离? [英] How to separate the selected item of two combobox with a single DataSource?

查看:102
本文介绍了如何两个组合框所选的项目与一个单一的数据源中分离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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;

这篇关于如何两个组合框所选的项目与一个单一的数据源中分离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆