473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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 9116
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Albert Valls Rovira | last post by:
Hello all... I'm puting two combo box in a form that both get their items from the same data table, and when in running time, I change the selected item from one combo box automatically changes...
0
by: Tarren | last post by:
Hi: I am getting this error "multiple controls with same ID were found" I found the following article from MS on this at http://support.microsoft.com/kb/834608 Anyone know where I can get...
1
by: Daves | last post by:
say I have a Datalist and each row has a image control with ID "MyImg". I am hiding/showing each image based on a result from the database. I need to find that particular img control to access it's...
3
by: Nathan Sokalski | last post by:
When I view any page in my application a second time, I recieve the following error: System.Web.TraceContext.AddNewControl(String id, String parentId, String type, Int32 viewStateSize) +313...
2
by: Tubs | last post by:
I am trying to use data binding to avoid having to write event handlers everywhere for my data transfer from controls to data source and all is working well except, i have a condition i would like...
7
by: John J. Hughes II | last post by:
I have a DataGridView with a TextBoxColumn. I setting the data source to a List<stringvalue in a static class. The list is filled from a background thread. So far all is fine and it works...
2
by: =?Utf-8?B?RGF2ZSBU?= | last post by:
I have a list box that is bound to an object data source. I added a column, say ColumnC, to my typed data set and for it's expression I entered ColumnA + ': ' + ColumnB When I preview the...
1
by: cppquester | last post by:
I got a forms library build from a data source with the designer. I want to use that as a custom widget (sevral instances). The designer included BindingSources for the controls in my forms...
0
by: asharda | last post by:
Hello, I have written a sample async code (using callback/async). I am now seeing a situation where-in if two messages are received at the same-time, both of them show-up in the data-buffer. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.