Two BindingSources with the Same DataSource Type

Two BindingSources with the Same DataSource Type

Old forum URL:

shaselsc posted on Wednesday, February 09, 2011


Two different combo boxes for a C# WinForms application that need to have a list of the same data. They need to be able to have different values at any given time, so they can't use the same BindingSource. I have a NameValueList business object that has an ID(Key) and Name(Value). I want to set the BindingSource to the same type of business object. When using the Visual Studio 2010 GUI to achieve this, the first one works correctly, but after adding the second and setting it to the NameValueList business object, I get a rather strange runtime error: "DataMember property 'Position' cannot be found on the DataSource." It happens on this line of code in the Designer code file for the form:


Is there a way to get around this or am I going about this the wrong way?


ajj3085 replied on Thursday, February 10, 2011

The DataSource for each drop down should be the same binding source, which will be where you set the list data (the shared list).

You then bind the SelectedItem (or SelectedValue) to the business object's property which is to be updated by the list when it changes.  You do this in the Propreties window for the dropdown and expand the (Data bindings) node.

shaselsc replied on Friday, February 11, 2011

Hi Andy,

Thanks for the reply. I tried setting them all to the same binding source. When that happens, anytime you change one drop down, the other changes as well. In my case, I need them to be able to be different values. One of them is a search criteria, and the other is a property of the business object. The business object is the Associate and the property is the ID of the Spouse, who's also an associate. It turns out I even needed a third drop down box as the users wanted to be able to bring up Associates by their ID, which also had to be sorted differently. I ended up creating a sort function using LINQ, which required me to create separate instances of the list anyway, so I used those different instances to set my DataSources for my combo boxes and setting the DisplayMember and ValueMember manually. I'm not sure if that's the ideal solution, but I went ahead and went with that for now. I'd be open for a better solution if you had any ideas though.

Thanks again,

ajj3085 replied on Saturday, February 12, 2011

Ok, looks like for some reason you need a different binding source for each combobox, but you can reuse the same exactly list BO as their data sources.

Copyright (c) Marimer LLC