Databinding a comboList to a DataView

Posted on 2006-04-15
Medium Priority
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
  • 2
  • 2
LVL 34

Accepted Solution

Sancler earned 1800 total points
ID: 16460744
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

ID: 16460831
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

ID: 16460895
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

ID: 16461036
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

850 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