VB.NET Listbox Multiple select

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a list box lstMy which is bound to a datatable dt.
The SelectionMode in the listbox is set to MultiSimple.

I want to run through the listbox and return all _values_ from the selected items. In other words, if it were to be a single select listbox i would just refer to it as lstMy.SelectedValue however in the multiple select I cannot do that. Plus I am running through the list using a for loop.

Logically my code should look like this:

for i = 0 to lstMy.Items.Count -1

if lstMy.Selected
return lstMy.Item(i).Value

next i

however, I can't make it work.

Any help will be greatly appreciated.
Thanks.
 
Dim ps As Object
For Each ps In ListBox1.SelectedItems
doSomethingWithSelectedItem
Next

The SelectedItems does not show in MSDN (at least the Jan04).

Lloyd Sheen

Alex Fimine said:
Hi,

I have a list box lstMy which is bound to a datatable dt.
The SelectionMode in the listbox is set to MultiSimple.

I want to run through the listbox and return all _values_ from the
selected items. In other words, if it were to be a single select listbox i
would just refer to it as lstMy.SelectedValue however in the multiple select
I cannot do that. Plus I am running through the list using a for loop.
 

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

Back
Top