Label box strings

jdjd1118

Member
Joined
Nov 30, 2005
Messages
12
Programming Experience
Beginner
Hello, I am trying to get exact strings from a list box and then saving to a text file. How do I get those strings into a variable to use? Thank you for your help.
 
this is how to get all items from listbox control while if you want to use certain item like all selected items you should iterate to the slectedItems collection ... however this will give you idea :)
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myStrings [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] i [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 0 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] ListBox1.Items.Count - 1
myStrings &= ListBox1.Items(i) & ControlChars.NewLine
[/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2]MessageBox.Show("Now you can proceed ""myStrings"" either to textBox or to text file")
[/SIZE][SIZE=2][COLOR=#008000]'i.e.
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].txtHolder.Text = myStrings[/SIZE]


HTH
Regards ;)
 

Attachments

  • getStringsFromListBox.zip
    23.8 KB · Views: 33
Note that the items as retrieved from a ListBox are Object references. If you put String objects in the ListBox in the first place then you should, strictly speaking, still cast the Object reference you get from the ListBox using CStr. The generic way to get the text displayed for a ListBox item regardless of what type that item is is:
VB.NET:
myListBox.GetItemText(myListBoxItem)
where myListBoxItem is an actual item in the ListBox, which may be SelectedItem or Items(i) or something like that.
 
Back
Top