AnswerBun.com

changing the value of one combobox causes the value of the other one changes

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 ?

Stack Overflow Asked by nnmmss on February 22, 2021

1 Answers

One Answer

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";

Correct answer by Kyle Wang on February 22, 2021

Add your own answers!

Related Questions

Laravel Slow queries

5  Asked on November 7, 2021 by squiggs

     

Display image that returns HTTP 503 in Firefox

2  Asked on November 7, 2021 by brainstone

       

Simple TCP listener on swift

1  Asked on November 7, 2021 by mr-park

       

check the type of the only child in react

1  Asked on November 7, 2021

 

Cannot update document using the NodeJS MongoDB driver

1  Asked on November 7, 2021 by niaz-m-sameer

   

Can not convert umlauts (Ü Ö Ä ü ö ä è é) to .utf8

2  Asked on November 7, 2021 by salome-tsiramua

       

elegant way of extracting option value when need it

1  Asked on November 7, 2021 by user804968

 

Sign PDF asynchronous using PDFBox

0  Asked on November 7, 2021 by lawrence-leung

         

Get non hidden element with previousElementSibling

2  Asked on November 7, 2021 by jens-trnell

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved.