All comboxes display the same item. Why?

Posted on 2006-05-26
Last Modified: 2010-08-05
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?
Question by:cdseteam
    LVL 24

    Expert Comment

    How about posting the smalles code sample which shows the mentioned behaviour?

    LVL 5

    Expert Comment


    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..

    LVL 31

    Expert Comment

    What needs to be done is to create a separate Datasource for each combobox, then you will have 10 separate "views".  
    LVL 2

    Accepted Solution


    your solution will work ONLY in web pages; 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;

    Author Comment

    Thanks. You sent me in the right direction...

    I went to 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."

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Title # Comments Views Activity
    countEvens challenge 2 46
    seriesUp challenge 7 79
    ClickOnce Install - Shortcut Question 3 38
    count7 challenge 12 52
    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    A short article about problems I had with the new location API and permissions in Marshmallow
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now