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?
LVL 2
zwiebeleAsked:
Who is Participating?
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.