• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

All comboxes display the same item. Why?

I have created 10 comboxes on one form and they all get their list from an array -

Form1.ComboBox1.DataSource = string_array

What is happens is that when I select an item in combobox1 all the other comboboxes automatically display the same thing. Why?

My other comboboxes are also set to get their data from the same array. but if I make them take data from another identical array same thing happens. Why?
0
cdseteam
Asked:
cdseteam
1 Solution
 
fridomCommented:
How about posting the smalles code sample which shows the mentioned behaviour?

Friedrich
0
 
vinodhsomasekharanCommented:
Hai,

Just verify whether the onchange event is same for all the comboboxes..??

If u r using html control..just verify the onchange event in their html tag..



regards
Vinu
0
 
moorhouselondonCommented:
What needs to be done is to create a separate Datasource for each combobox, then you will have 10 separate "views".  
0
 
VeryNiceManCommented:
hi;

your solution will work ONLY in web pages asp.net; and it will fail on Windows Forms.
explaining why; will need long pages and pages. if you want to know why this happen then i will try to find some websites that explains this behaviour.

the solution without explaining why is as follows:

 Private Sub Form9_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a() As String = New String() {"a", "b", "c", "d", "e", "f"}

        ComboBox1.BindingContext = New BindingContext
        ComboBox1.DataSource = a

        ComboBox2.BindingContext = New BindingContext
        ComboBox2.DataSource = a

        ComboBox3.BindingContext = New BindingContext
        ComboBox3.DataSource = a

        ComboBox4.BindingContext = New BindingContext
        ComboBox4.DataSource = a

        ComboBox5.BindingContext = New BindingContext
        ComboBox5.DataSource = a

        ComboBox6.BindingContext = New BindingContext
        ComboBox6.DataSource = a
    End Sub


the above will work for ANY number of ComboBox on your form; just keep adding they; you can also try to put the whole thing in a loop or whatever you like.

hope that helps;
best regards;
0
 
cdseteamOperations Manager - End User ComputingAuthor Commented:
Thanks. You sent me in the right direction...

I went to http://www.akadia.com/services/dotnet_unshare_datasource.html and found some more info which helped me.

"If you have two controls bound to the same datasource, and you do not want them to share the same position, then you must make sure that the BindingContext member of one control differs from the BindingContext member of the other control. If they have the same BindingContext, they will share the same position in the datasource.

If you add for example a ComboBox and a ListBox to a form, the default behavior is for the BindingContext member of each of the two controls to be set to the Form's BindingContext. Thus, the default behavior is for the ListBox and ComboBox to share the same BindingContext, and hence the selection in the ComboBox is synchronized with the current row of the ListBox. If you do not want this behavior, you should create a new BindingContext member for at least one of the controls."
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now