我已定义BindingSource
:
public System.Windows.Forms.BindingSource bsContractors;
this.bsContractors.DataSource = typeof(Contractor);
然后ComboBox
DataSource
定义如下:
private System.Windows.Forms.ComboBox cmbConstructionContractors1;
this.cmbConstructionContractors1.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.bsProject, "Id", true));
this.cmbContractors1.DataSource = this.bsContractors;
this.cmbContractors1.DisplayMember = "Name";
this.cmbContractors1.ValueMember = "Id";
this.cmbContractors1.SelectedIndexChanged += new System.EventHandler(this.cmbContractor1Selected);
这很好用。
我使用相同的DataSource在另一个ComboBox
上定义了另一个Form
:
this.cmbContractorName2.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", myView.bsProject, "Id", true));
this.cmbContractorName2.DataSource = projectView.bsContractors;
this.cmbContractorName2.ValueMember = "Id";
this.cmbContractorName2.DisplayMember = "Name";
this.cmbContractorName2.SelectedIndexChanged += new System.EventHandler(this.cmbContractor2Selected);
当显示第二个ComboBox
时,选择了某个内容的第一个ComboBox
将重置为第一个条目,该条目为空。
如果我按下第一个ComboBox
,列表仍然存在,只是'忘记'选择了哪一个。
修改:我发现在显示第二个ComboBox
时,第一个ComboBox1
的EventHandler会被分配到cmbContractors2Selected
而不是原来的cmbContractors1Selected
答案 0 :(得分:1)
尝试给它自己的绑定对象:
this.cmbContractorName2.DataSource = new BindingSource(projectView.bsContractors, null);
这会将货币经理分开。