Listbox display all items

Talk2Tom11

Centurion
Joined
Feb 22, 2004
Messages
144
Location
Westchester, NY
ok i have a listbox with a few rows of data. I am having the data be read as a string into a word document.

I want to be able to read the whole listbox as a string.

So far I have only been able to get it to read one line. This is the code i used for that... listbox1.SelectedItem. Is there anyway to have it use the whole thing and not just one selected item???
 
You should be able to iterate through all the items (the Items property) using a For Each loop, and join them together into one long string, using whatever you like as a separator, though it will probably be a comma or a new line. How is the ListBox populated? I'm not sure if this would work with a databound ListBox.
 
As marble_eater said. You should use the Items property in Web Application. But it would be best to use the SelectedItems property in a Windows Application. I believe it would work even if you're using a databound listbox because binding means filling the Items. So we should be able to access the Items of the ListBox.
 
Using SelectedItems would only enumerate selected items. Assuming you would like to enumerate all items, you should use the Items property.
 
Using SelectedItems would only enumerate selected items. Assuming you would like to enumerate all items, you should use the Items property.

Thx for the correction. I kinda miss the "using the whole thing" in the question. I'm not adding anything more to this thread. Although I was wondering why would Talk2Tom11 loads the data to a listbox when in the end the items will be concatenate as a whole string. :confused:
 
Back
Top