Multiple controls bound to same data Source

A

Ashutosh

Hi,
I have a un-typed table and 5 combo box on the form. All these combo box
have this table as the data source. Now I want to be able to select
different values using the 5 combo box. But when I change the value in
one combo box, it changes the value in all other combo box.

How can I make all the 5 combo box retain their individual (different
values)?

Thanks & Regards,
Ashutosh
 
M

Marc Gravell

The issue is that the currency manager is shared among any instances who
share a binding-context and have the same reference for DataSource.

You could try creating 5 BindingSource instances, and assign one
BindingSource as the source for each control (and give each
BindingSource the same DataSource)?

Marc
 
G

GArlington

Hi,
I have a un-typed table and 5 combo box on the form. All these combo box
have this table as the data source. Now I want to be able to select
different values using the 5 combo box. But when I change the value in
one combo box, it changes the value in all other combo box.

How can I make all the 5 combo box retain their individual (different
values)?

Thanks & Regards,
Ashutosh

Bound controls are there to make gets and updates easy, if all you
want is a snapshot of the value than this is what you need to do, get
the value and then display it, do NOT bind the control...
 
M

Marc Gravell

i.e.

// fails (all change together)
string[] data = { "abc", "def", "ghi" };
Application.Run( new Form { Controls = {
new ListBox {DataSource = data, Dock = DockStyle.Left},
new ListBox {DataSource = data, Dock = DockStyle.Right}
}});

// works (change independently)
string[] data = { "abc", "def", "ghi" };
Application.Run( new Form { Controls = {
new ListBox {DataSource = new BindingSource(data, ""),
Dock = DockStyle.Left},
new ListBox {DataSource = new BindingSource(data, ""),
Dock = DockStyle.Right}
}});
 
J

\Ji Zhou [MSFT]\

Hello Ashutosh,

Thanks for using Microsoft Newsgroup Support Service, my name is Ji Zhou
[MSFT] and I will be working on this issue with you.

I can reproduce your issue on my side. And I agree with Marc's comment. The
reason that all of the five combobox values keep synchronizing is they
share the same binding context. So, the current selected item will be same
for them. The easiest way to avoid this is creating several BindingContext
instances for each of the comboboxs. Codes look like the following,

private void Form1_Load(object sender, EventArgs e)
{
System.Data.DataTable dt = new DataTable();
dt.Columns.Add("Item");
dt.Rows.Add(new object[]{"Item1"});
dt.Rows.Add(new object[]{"Item2"});
dt.Rows.Add(new object[]{"Item3"});
dt.Rows.Add(new object[]{"Item4"});
dt.Rows.Add(new object[]{"Item5"});

this.comboBox1.DataSource = dt;
this.comboBox1.DisplayMember = "Item";


this.comboBox2.DataSource = dt;
this.comboBox2.DisplayMember = "Item";
this.comboBox2.BindingContext = new BindingContext();

this.comboBox3.DataSource = dt;
this.comboBox3.DisplayMember = "Item";
this.comboBox3.BindingContext = new BindingContext();

this.comboBox4.DataSource = dt;
this.comboBox4.DisplayMember = "Item";
this.comboBox4.BindingContext = new BindingContext();

this.comboBox5.DataSource = dt;
this.comboBox5.DisplayMember = "Item";
this.comboBox5.BindingContext = new BindingContext();
}

I have tested the above codes on my side, which works correctly. Would you
mind testing on your side and tell me if it helps? If you have any
questions or concerns, please feel free to let me know and I will try my
best to provide assistance.

Have a nice day!


Best regards,
Ji Zhou ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top