Databinding a comboList to a DataView

Posted on 2006-04-15
Last Modified: 2010-04-23
I have a dataview containing rows of data. The data, lets say, contains a number of categories (several in category1, a couple in category2 etc). On my form, I have different comboBoxes for each category for which I want to list.

How do I, through databinding, list the data in each category to their respective comboBoxes? I think I'm nearly there, just need help at ????

What I have so far:

MyDataView.RowFilter = "CategoryColumn = 'CategoryValue'"
ComboBox1.DataBindings.Add("????", MyDataView, "DataViewColumn")

  'repeat the above changing the Category and ComboBox's accordingly

If I replace ???? with:
   - "Text", I just get the first row
   - "Items" throws an exception as the Items property is read only
   - "DisplayMember" nothing

Question by:IvanHowarth
    LVL 34

    Accepted Solution

    You do your bindings in a different way for controls that contain "lists" - like comboboxes.  Try this

       ComboBox1.DataSource = MyDataView
       ComboBox1.DisplayMember = "DataViewColumn"

    and similar for your other categories/comboboxes.

    Often, when you are using comboboxes, you will want them to display some meaningful text but actually return some coded data.  If that's the case here, you might also want

       ComboBox1.ValueMember = "DifferentDataViewColumn"


    Author Comment

    Since posting the question, I have (found and) used your first suggestion which does give the desired result. I just thought there might then be a way of doing it in a single line. Obviously not.

    Thanks anyway.

    Author Comment

    Problem with the above:

    Because all the different categories are in the same column (input by user at runtime), all my comboboxes are listing all the same items. Is there a way of getting each of the comboboxes to filter (and thus retain) their own data from this one column?

    LVL 34

    Expert Comment

    Is there a way of getting each of the comboboxes to filter (and thus retain) their own data from this one column?

    I don't know of a way to get the combobox itself to filter.  But if you use a different dataview for each combobox, you could apply the filter to the dataview, I think.


    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    755 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

    17 Experts available now in Live!

    Get 1:1 Help Now