Link to home
Start Free TrialLog in
Avatar of bradderick
bradderickFlag for Australia

asked on

VB.net store/select values in multiline listbox based on DB tables.

Hi,

I have a pretty simple VB.net page displaying a logged in user's preferences that I am trying to add a new control to. I'm adding a multi line listbox which loads a list of countries from a table (lets say tblCountry). This table contains reference data of country names and country IDs.

However, when this listbox is loaded, I want it to select countries based on the current user's "preferred countries". Which means I need to store the user's selected countries in a different table somewhere - not the tblCountry table.

I have no problems loading the country list from tblCountry and binding it to the listbox but I can't work out how to also load and store the selected countries into another table and update the selected values of the multiline listbox on this user preferences page.

Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of jef06
jef06
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bradderick

ASKER

Okay that sounds like it would work. But how to set the Selected property for the appropriate countries in the listbox then?

Currently the DataTextField property is set to the field  "CountryName" and DataValueField property is set to "iCountryID" before the databind.

How do I set the selected items based on the outerjoin you mentioned?
If you can select multiple countries use the left outer join and use LisItem and for each element check if there is a value, but it looks like you can select only one country in your case, it might be better to create a method that return the country selected and you set the SelectedIndex in looping threw your values.
No actually you were right in the first place - the user can select multiple countries. Can you wlaborate a little more about the listitem method?

Any example code would be excellent!