I have BindingSource
defined:
public System.Windows.Forms.BindingSource bsContractors;
this.bsContractors.DataSource = typeof(Contractor);
and then a ComboBox
with a DataSource
defined like so:
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);
This works fine.
I have another ComboBox
defined on another Form
using the same DataSource:
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);
When this 2nd ComboBox
is displayed, the first ComboBox
, which has something selected, gets reset to the first entry, which is blank.
If I pull down on the first ComboBox
, the list is still there, it just 'forgot' which one was selected.
Edit: I've discovered that when displaying the 2nd ComboBox
, the EventHandler of the 1st ComboBox1
somehow gets assigned to cmbContractors2Selected
instead of the original cmbContractors1Selected