By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,854 Members | 876 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,854 IT Pros & Developers. It's quick & easy.

Retrieve Selected Items in a Listbox

P: n/a
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
Nov 16 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

"Randy" wrote:
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
Nov 16 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.