• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Selected listbox items

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

bdf24

Senior Member
Joined
Feb 15, 2001
Location
Harford, WI.
If you don't mind I need a little help.
I'm taking Introduction to Visual Basic this semester at school.
I need to complete a project that requires multiple items of a listbox to be displayed in a label. I can get the single items to display by doing this:

resultLabel.Text = Convert.ToString(namesListBox.SelectedItem)

I figured to get multiple selected items to show I would do the following:

resultLabel.Text = Convert.ToString(namesListBox.SelectedItems) but it doesn't work. This is with 5 items added to the list box.

I'm using visual basic 2005, I hope I've given you enough information.

Thanks in advance for your help.
 
I don't really know much about visual basic, but based on my other programming knowledge, it sounds like namesListBox.SelectedItems would be returned as an array since it's multiple items. You would have to loop through each item in the array returned by calling namesListBox.SelectedItems to display them in a label.

Basically, what you would do is,
1. Find out how many items are selected. (By finding out the count in the array returned by .SelectedItems)
2. Loop through each item in that array.
3. Each loop appends the converted ListBox to the label.
 
Back