Question Reading from a saved ListBox

Pirahnaplant

Well-known member
Joined
Mar 29, 2009
Messages
75
Programming Experience
3-5
I am saving a ListBox to a file like this:

VB.NET:
Dim Strm As New StreamWriter(FileLocation)
Strm.Write(ListBoxName)
Strm.Close()

How can I read the file that was saved back into the ListBox?
 
That wont do you any good because the Strm.Write() method calls .ToString on your ListBoxName so none of the items in the list box are written to the file.

What you should be doing is looping the items in the listbox and writing those to the file in the loop. Then to get them back, loop the file and add each back to the listbox.

This is the most simplistic way of handling this, there are of course better ways (still following the same overall methodology) to write the data, xml is one example.
 
Back
Top