473,378 Members | 1,415 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,378 software developers and data experts.

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 11425
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.BindingContext = new BindingContext();
comboBox2.BindingContext = new BindingContext();
comboBox3.BindingContext = 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.com

"Matt" <ma***********************@fujifilmsericol.comwrot e in message
news:11**********************@o5g2000hsb.googlegro ups.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.guard.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.BindingContext = new BindingContext();
comboBox2.BindingContext = new BindingContext();
comboBox3.BindingContext = 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.com

"Matt" <matthew.macdonald-wall...@fujifilmsericol.comwrote in message

news:11**********************@o5g2000hsb.googlegro ups.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
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...
0
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...
1
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...
3
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...
1
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...
3
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...
5
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...
3
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...
7
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.