Groups | Blog | Home
all groups > dotnet windows forms > march 2008 >

dotnet windows forms : Persisting field form values


Inictus
3/26/2008 3:51:43 PM
[quoted text, click to view]

Binding the form elements to a simple database would be the easiest
kimiraikkonen
3/26/2008 3:57:26 PM
[quoted text, click to view]

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)
John
3/26/2008 10:22:46 PM
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

BlackWasp
3/26/2008 10:46:48 PM
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.

--

BlackWasp
www.blackwasp.co.uk


[quoted text, click to view]
Herfried K. Wagner [MVP]
3/26/2008 11:56:19 PM
"John" <info@nospam.infovis.co.uk> schrieb:
[quoted text, click to view]

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

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
AddThis Social Bookmark Button