Reputation: 2974
I am two Combobox which are populated with a view of a table like following
recieverComboBox.DataSource = myDataSet.Tables[0].DefaultView;
recieverComboBox.DisplayMember = "UserPosition";
recieverComboBox.ValueMember = "ID";
recieverUnReadComboBox.DataSource = myDataSet.Tables[0].DefaultView;
recieverUnReadComboBox.DisplayMember = "UserPosition";
recieverUnReadComboBox.ValueMember = "usr_Id";
when I change the value of each of them, the value of the other one changes automatically. why is that ?
Upvotes: 0
Views: 41
Reputation: 3767
Here are two ways to avoid this issue.
Solution A:
Use BindingSource as the DataSource of ComboBox.
recieverComboBox.DataSource = new BindingSource(myDataSet.Tables[0].DefaultView, null);
recieverComboBox.DisplayMember = "UserPosition";
recieverComboBox.ValueMember = "ID";
recieverUnReadComboBox.DataSource = new BindingSource(myDataSet.Tables[0].DefaultView, null);
recieverUnReadComboBox.DisplayMember = "UserPosition";
recieverUnReadComboBox.ValueMember = "usr_Id";
Solution B:
Call method DataTable.Copy
recieverComboBox.DataSource = myDataSet.Tables[0].Copy();
recieverComboBox.DisplayMember = "UserPosition";
recieverComboBox.ValueMember = "ID";
recieverUnReadComboBox.DataSource = myDataSet.Tables[0].Copy();
recieverUnReadComboBox.DisplayMember = "UserPosition";
recieverUnReadComboBox.ValueMember = "usr_Id";
Upvotes: 1