473,778 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple ComboBoxes, one data source

Hi all, me again! :)

I've now got an issue with combo boxes. Basically, I have a number of
items that I want a user to pick from a single list. It's basically
along the lines of:

Fruit 1: [value]
Fruit 2: [value]
Fruit 3: [value]

the values are setup in a string array called fruitList[]

I have set the datasource on all the comboBoxes to be fruitList[]
however when I change the selected item in on comboBox, it changes in
all the others as well!

Is there a way that I can use one array across multiple comboBoxes
without having it change across the boxes every time? An example is
as follows:

Fruit 1: [Apple]
Fruit 2: [Apple]
Fruit 3: [Apple]

I want to make fruit 1 an apple, fruit 2 a bannana and fruit 3 a pear,
however when I select bannana for fruit two, I get the following:

Fruit 1: [Bannana]
Fruit 2: [Bannana]
Fruit 3: [Bannana]

The comboBoxes are named comboBox1 to comboBox8 (lazy I know, but this
is just a proof of concept at the moment!)

All help is welcomed!

May 4 '07 #1
2 11459
Matt,

This is simple. You can bind all the combo boxes to the array, you just
have to make sure that each combobox uses a separate BindingContext.

So, for your comboboxes, you want to do:

comboBox1.Bindi ngContext = new BindingContext( );
comboBox2.Bindi ngContext = new BindingContext( );
comboBox3.Bindi ngContext = new BindingContext( );

When they are created, they inherit from the control that is hosting
them. Since you didn't specify it, it are all using the context of the
control/form that they are hosted in, and that's why when you change one
combo box, they all change.

You could also get around this by copying the contents of the array into
a new array for each combobox. This will cause the binding context to look
at the data as separate data sources, and they will have their own binding
context.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Matt" <ma************ ***********@fuj ifilmsericol.co mwrote in message
news:11******** **************@ o5g2000hsb.goog legroups.com...
Hi all, me again! :)

I've now got an issue with combo boxes. Basically, I have a number of
items that I want a user to pick from a single list. It's basically
along the lines of:

Fruit 1: [value]
Fruit 2: [value]
Fruit 3: [value]

the values are setup in a string array called fruitList[]

I have set the datasource on all the comboBoxes to be fruitList[]
however when I change the selected item in on comboBox, it changes in
all the others as well!

Is there a way that I can use one array across multiple comboBoxes
without having it change across the boxes every time? An example is
as follows:

Fruit 1: [Apple]
Fruit 2: [Apple]
Fruit 3: [Apple]

I want to make fruit 1 an apple, fruit 2 a bannana and fruit 3 a pear,
however when I select bannana for fruit two, I get the following:

Fruit 1: [Bannana]
Fruit 2: [Bannana]
Fruit 3: [Bannana]

The comboBoxes are named comboBox1 to comboBox8 (lazy I know, but this
is just a proof of concept at the moment!)

All help is welcomed!

May 4 '07 #2
On 4 May, 20:11, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
Matt,

This is simple. You can bind all the combo boxes to the array, you just
have to make sure that each combobox uses a separate BindingContext.

So, for your comboboxes, you want to do:

comboBox1.Bindi ngContext = new BindingContext( );
comboBox2.Bindi ngContext = new BindingContext( );
comboBox3.Bindi ngContext = new BindingContext( );

When they are created, they inherit from the control that is hosting
them. Since you didn't specify it, it are all using the context of the
control/form that they are hosted in, and that's why when you change one
combo box, they all change.

You could also get around this by copying the contents of the array into
a new array for each combobox. This will cause the binding context to look
at the data as separate data sources, and they will have their own binding
context.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard .caspershouse.c om

"Matt" <matthew.macdon ald-wall...@fujifil msericol.comwro te in message

news:11******** **************@ o5g2000hsb.goog legroups.com...
Hi all, me again! :)
I've now got an issue with combo boxes. Basically, I have a number of
items that I want a user to pick from a single list. It's basically
along the lines of:
Fruit 1: [value]
Fruit 2: [value]
Fruit 3: [value]
the values are setup in a string array called fruitList[]
I have set the datasource on all the comboBoxes to be fruitList[]
however when I change the selected item in on comboBox, it changes in
all the others as well!
Is there a way that I can use one array across multiple comboBoxes
without having it change across the boxes every time? An example is
as follows:
Fruit 1: [Apple]
Fruit 2: [Apple]
Fruit 3: [Apple]
I want to make fruit 1 an apple, fruit 2 a bannana and fruit 3 a pear,
however when I select bannana for fruit two, I get the following:
Fruit 1: [Bannana]
Fruit 2: [Bannana]
Fruit 3: [Bannana]
The comboBoxes are named comboBox1 to comboBox8 (lazy I know, but this
is just a proof of concept at the moment!)
All help is welcomed!
Nicholas,

That worked a treat! Thanks!

M.

May 4 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1969
by: Kathy | last post by:
In my custom menu one menu item opens a form to add new Makes to TblMakes and another menu item opens a form to add new Models to TblModels. I have a form that has a combobox for Makes and a combobox for Models. In both comboboxes I use the NotInList event and code to allow users to enter Makes and Models that are not in the database. When the form is open, I want to limit the users to entering new Makes and Models in the comboboxes and not...
0
1942
by: johnson_cy | last post by:
I am using Access 2000. My main form has a record source of a table (employeeTbl with key of . It is filtering the record results. My subform and mainform have the link child/link master set to and the source object is the subform. My subform record source is a query from another table (vacationTbl). FYI: I was filtering on the subform, but removed it and replaced with
1
1616
by: cnakam | last post by:
Greetings I have a simple MS-Access database with 2 tables in a many-to-many relationship. One is a table of diseases and one is a table of symptoms. I need to create a form where all the symptoms show on the left side with a checkbox. When one checkbox is clicked, the diseases associated with the symptom show on the left side. If another disease is selected, only the diseases associated with both symptoms are displayed, and so on. What...
3
1480
by: Craig G | last post by:
are there any decent 3rd Party Comboboxes/DropDownLists for ASP.NET that will allow users to enter data into them like in VB.NET? basically i want a combobox that i can populate with a list of values from a table. then the user can then enter the value into the combobox and it will move to the nearest match Cheers, Craig
1
2798
by: TheMadHatter | last post by:
I have an array of a custom obj which I am trying to use in multiple comboBoxes without creating multiple copies, but if I put the datasource of the comboboxes to the same array, then at runtime if I pick change a combobox, all of them change to that value. I am guessing that it is because all the comboboxes are using the same Ilist interface, and the behind-the-sceens variables. Now, I could create my own wrapper class to wrap the...
3
1877
by: Randy | last post by:
I have a routine that creates a series of comboboxes, each of which is bound to a common dataview. Everything used to work fine, but now, when I change the value of any of the comboboxes, the value in ALL of the comboboxes changes to the new value. I have boiled down the code to the simplest lines and placed it on its own form, but I still get the same behavior. I have stepped through each line of code, and I don't see any other lines...
5
4057
by: Anthony Bollinger | last post by:
I have two tables in a master-detail relationship. When I make a selection in one combobox, how do I have it display the values from a second combobox? Each table has a key and a text value for each record. I don't yet see the way to update the list of values in the second combobox. Thanks for any input, Tony
3
2606
by: Major Doug | last post by:
Hello: situation--I have a research database. Each record in the database consists of 10 fields. I used access97 to rack/stack my database; very easy in the beginning. I created a form with a combobox. Using some information I found through this forum, I created the comboxbox in the form's header linked to textboxes in the form's detail. I could click on the column and see the linked data populate the 10 textboxes. I could easily maneuver...
7
13531
by: JTC^..^ | last post by:
When i attempt to bind to the "Text" and "Value" property of a combobox on a windows form the value is reset when I leave the combobox. The comboboxes contain the correct Text and Values. I know this as the Value property binds correctly on it own. It is only when I bind the "Text" and "Value" that the issue occurs. The following sample code includes my custom classes and the Form Clode. I have several comboboxes and customer classes...
0
9464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10061
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8954
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5368
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.