On Mar 27, 12:22 am, "John" <i...@nospam.infovis.co.ukwrote:
Hi
I have a form with a couple of text boxes and a list box. The user is able
to type text in text boxes and add elements to the list box. My question is;
how can I persist the values in these fields so they remain when the form is
closed and opened again by the user, either in the current session of the
app or after closing the app and rerunning it?
Thanks
Regards
You can store listbox content in a text file, and there are other ways
such as XML serialization, db...
See this that contains reading and writing listbox content into a
textfile:
To store listbox content in a text file:
Dim ItemArray(Me.ListBox1.Items.Count - 1) As Object
Me.ListBox1.Items.CopyTo(ItemArray, 0)
Dim Data As String = Join(ItemArray, Environment.NewLine)
My.Computer.FileSystem.WriteAllText("c:\data.txt", Data, False)
The parameters of WriteAllText method are up to you (append, data,
path...)
But remember that, your text file will get bigger and unresponsive due
to large amount of text lines over the time, then you may want to
create a new text file.
To get the content of textfile into your listbox:
Dim reader As String
reader = My.Computer.FileSystem.ReadAllText_
("c:\data.txt")
Dim strs() As String
strs = Split(reader, Environment.NewLine)
For Each s As String In strs
ListBox1.Items.Add(s)
Next