470,863 Members | 1,152 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,863 developers. It's quick & easy.

Multiple controls bound to same data Source

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
Nov 3 '08 #1
5 8832
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
Nov 3 '08 #2
On Nov 3, 12:16*pm, Ashutosh <smbs-m...@nospam.nospamwrote:
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...
Nov 3 '08 #3
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}
}});
Nov 3 '08 #4
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 (v-****@online.microsoft.com, 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:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#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/...tance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 4 '08 #5
Thanks Marc!!

Marc Gravell wrote:
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
Nov 4 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Albert Valls Rovira | last post: by
1 post views Thread by Daves | last post: by
3 posts views Thread by Nathan Sokalski | last post: by
2 posts views Thread by =?Utf-8?B?RGF2ZSBU?= | last post: by
1 post views Thread by cppquester | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.