adding listbox selected items

L

lord.zoltar

Hello
I'm trying to programmatically set a listbox to have several items
selected when it is loaded. Which items are selected is based on a
saved user setting.
Right now, I'm trying:
Me.my_ListBox.SelectedIndices.Add(item)
This throws exceptions.
What is a safe way to add indices to the SelectedIndices list?
 
G

Guest

lord.zoltar,

From your example, it looks like you have the items that should be selected.
In that case:

Me.my_ListBox.SelectedItems.Add(item)

Kerry Moorman
 
T

Tim Patrick

You can use the ListBox control's SetSelected method. Pass it the position
of the list item, and a boolean value, True in this case.

ListBox1.SetSelected(itemPosition, True)

Make sure that you have also set the SelectionMode property for the control
as needed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top