Retrieve Selected Items in a Listbox

R

Randy

Hi,
I have a listbox that allows multiple selections. I need to loop
through each selection and execute code based on the text of the
item. I'm sure that this is really simple, but I can't quite figure
out how to retrieve the text of each item. Here is the idea:

For x As Integer = 0 To lbx.SelectedItems.Count - 1
MessageBox.Show(lbx.SelectedItems.Item(x))
Next

I have tried a lot of different approaches to this, but I cannot
figure out how to simply retrieve the text of each selected item.

Can anybody help?
Thanks,
Randy
 
G

Guest

Randy,

Here are a couple of ways:

For i As Integer = 0 To ListBox1.SelectedItems.Count - 1
MsgBox(ListBox1.SelectedItems(i).ToString)
Next


For Each itm As Object In ListBox1.SelectedItems
MsgBox(itm.ToString)
Next

Kerry Moorman
 

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