Talk2Tom11 Posted February 21, 2007 Posted February 21, 2007 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??? Quote
Leaders snarfblam Posted February 21, 2007 Leaders Posted February 21, 2007 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. Quote [sIGPIC]e[/sIGPIC]
amir100 Posted February 23, 2007 Posted February 23, 2007 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. Quote Amir Syafrudin
Leaders snarfblam Posted February 23, 2007 Leaders Posted February 23, 2007 Using SelectedItems would only enumerate selected items. Assuming you would like to enumerate all items, you should use the Items property. Quote [sIGPIC]e[/sIGPIC]
amir100 Posted February 26, 2007 Posted February 26, 2007 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: Quote Amir Syafrudin
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.