【发布时间】:2011-07-13 11:20:14
【问题描述】:
我有绑定列表:
BindingList<string> sampleList = new BindingList<string>();
sampleList.Add("aaa");
sampleList.Add("bbb");
用作两个组合框的数据源:
comboBox1.DataSource = sampleList;
comboBox2.DataSource = sampleList;
当我在其中一个组合框中更改选择时,第二个也会受到影响。我怎样才能让他们保持独立?
编辑:
由于一些“热”的 cmets,我必须做一些澄清:
- 是 windows 窗体代码
- 有可能
- 背后没有其他逻辑/代码
- 我使用的是 .NET 2.0
完整代码来源:
public partial class Form1 : Form
{
BindingList<string> sampleList;
public Form1()
{
InitializeComponent();
sampleList = new BindingList<string>();
sampleList.Add("aaa");
sampleList.Add("bbb");
comboBox1.DataSource = sampleList;
comboBox2.DataSource = sampleList;
}
}
【问题讨论】:
-
这是不可能的,因为 BindingList 没有关于组合框中所选项目的信息。一定有其他事情发生。
-
能否提供更改所选值的代码?
-
你会想知道的。如今,人们使用反对票的速度非常快。
-
我没有投反对票,但我猜是因为缺少很多信息。正如我已经评论过的,OP 所暗示的不是真的,他的问题一定出在他没有显示的代码中。
-
@Daniel Hilgarth,一个合理的评论。我对我的暗示是,人们很快就会在不等待澄清的情况下投反对票。他们期待完美的问题。