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

DataBinding to a MultiSelect List Box in VB.Net

I have Items that can be put into multiple categories so I have two tables called Items (primary key column is ID) and Categories (primary key columns are Item_ID and Category).  I want to bind the Category.Category Column to a multi-select listbox.  How do I do this?
0
zwiebele
Asked:
zwiebele
  • 3
  • 2
1 Solution
 
TorrwinCommented:
When you drag the list box onto your form, set the SelectionMode property to "MultiSimple" or "MultiExtended".

Now, you fill a dataset with your query, yours would probably be "SELECT CATEGORY FROM CATEGORY".

Then set the dataset as the listbox's data source

Listbox1.datasource = myDataset

0
 
zwiebeleAuthor Commented:
Torrwin,

I need to clarify my post.  I have the listbox populated with all the possible categories.  

How do I get the dataset that contains my Item and Category tables to reflect the selections of the list box?  Do i need to loop through the selecteditems and manually add or remove them or is there a way to automatically do that through databinding?
0
 
TorrwinCommented:
Ok, just to double check.  If the user selects an item in your listbox you want to remove or add it to the dataset?
0
 
zwiebeleAuthor Commented:
Torrwin,

That's correct.  When a user selects/deselects an item in the listbox I want to add/remove a row from the Categories (primary key columns are Item_ID and Category) table of the dataset.  

Can I do this automaticaly or do i have to write my own code?
0
 
TorrwinCommented:
Well you can do it semi-automatically like here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconupdatingdatabasewithdataadapterdataset.asp

I usually just write my own code though, but thats just personal preference.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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