Synchronised ComboBoxes

D

Doug Bell

Hi,
I have a "Settings" form with a number of Combo Boxes.

Several of these Combos have their DataSource set to an ArrayList.
I have found that changing the selected text for one combo also changes the
other combo boxes displayed text.

Why does this happen?
Do I need to create a separate ArrayList for each Combo?

Thanks Doug
 
B

Bart Mermuys

Hi,

Doug Bell said:
Hi,
I have a "Settings" form with a number of Combo Boxes.

Several of these Combos have their DataSource set to an ArrayList.
I have found that changing the selected text for one combo also changes
the
other combo boxes displayed text.

Why does this happen?

By default controls use their parent's BindingContext. If the
BindingContext, DataSource and DataMember are the same, then the same
CurrencyManager will be used which mantains the position.
Do I need to create a separate ArrayList for each Combo?

You can, but an alternative is to create a new BindingContext for each
ComboBox preferably before binding:

Dim someList As New ArrayList
' ....
'.....
comboBox1.BindingContext = new BindingContext
comboBox1.DataSource = someList

comboBox2.BindingContext = new BindingContext
comboBox2.DataSource = someList


HTH,
Greetings
 
C

Cor Ligthert [MVP]

Doug,

No it is easier to use a datatable. That has his own defaultview, however
you can add as much seperated new dataviews as you want.

I hope this helps,

Cor
 
D

Doug Bell

Hi Bart,

Thanks. Works great!

Bart Mermuys said:
Hi,



By default controls use their parent's BindingContext. If the
BindingContext, DataSource and DataMember are the same, then the same
CurrencyManager will be used which mantains the position.


You can, but an alternative is to create a new BindingContext for each
ComboBox preferably before binding:

Dim someList As New ArrayList
' ....
'.....
comboBox1.BindingContext = new BindingContext
comboBox1.DataSource = someList

comboBox2.BindingContext = new BindingContext
comboBox2.DataSource = someList


HTH,
Greetings
 
D

Doug Bell

Cor Thanks,
I could have constructed a DataTable but it was easier to build an Array
list as I had 18 Combos with 8 different sets of data that each needed a
first row added ("Select xxxx") to the original DataTables and the original
DataTables were required in tact.

So I built a function to create the 8 different array lists.

Bart answered my question explaining about the inheritance of the Currency
manager.

Doug
 

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