[SOLVED] Multiple ComboBoxes with same DataSource selectedValue

Answered Closed
0
0

I’ve implemented a Tlp with some ComboBoxes which are bound to the same DataSource. The Goal is to allow to select some kind of Master- and SubItems.

When the selectedValue of one of the ComboBoxes changes, all other are changing too. Is this a Bug or is it normal behavior ?

Have attached an Example.

 

Best Regards

Corvin

Attachment
  • You must to post comments
Best Answer
0
0

Hi,

I had seen the same and I had discussed it with Luca, who found the best solution. Instead of giving each combobox as Datasource a the same IList<Item>,  give a new BindingSource, the Datasource of which is your IList<item>.

i.e.,

var myList = new List<Item> { new Item { ID = 1, Name = “Name1” }, new Item { ID = 2, Name = “Name2” } };

var C1 = new ComboBox();
C1.ValueMember = “ID”;
C1.DisplayMember = “Name”;
C1.DataSource = new BindingSource(myList, null};   // NOT C1.DataSOurce = myList;

var C2 = new ComboBox();
C2.ValueMember = “ID”;
C2.DisplayMember = “Name”;
C2.DataSource = new BindingSource(myList, null};   // NOT C2.DataSOurce = myList;

Best regards,
Alex

 

 

 

  • You must to post comments
0
0

Ah, thank you Alex !

Will give it a try.

  • You must to post comments
Showing 2 results