Persisting field form values

J

John

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
 
B

BlackWasp

To persist between sessions you need to store the data somewhere other than
the application. The location you choose will depend upon the application,
the environment and whether you need the stored information to follow the
user around the network.

Usual suspects for storage spaces are:

* An XML configuration file
* The registry
* A database

but of course there are many other possibilities too.
 
I

Inictus

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

Binding the form elements to a simple database would be the easiest
way.
 
H

Herfried K. Wagner [MVP]

John said:
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?

Application Settings Overview
<URL:http://msdn2.microsoft.com/en-us/library/k4s6c3a0.aspx>
 
K

kimiraikkonen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top