Click to See Complete Forum and Search --> : Save content of listbox


Junday
June 4th, 2009, 01:09 PM
Hello.

I am using Visual Studio 2008 which should be VB.NET 3.0 language.

I have searched and searched for finding the answer on saving content / items in a listbox with strings. As you know the code for saving a text in textbox and get information again in application is:


Dim stringtxt As String

stringtxt = textbox1.text
My.Settings.mytextstring = stringtxt


and load it you do

textbox1.text = My.Settings.mytextstring


But i do not know how to save and load the items in a listbox - is it even possible?

Thank you for your help.

sorry for my bad english, i am from denmark

DataMiser
June 4th, 2009, 02:38 PM
To save you would loop through the items in the listbox one by one until you reach the end. To load you would clear the list box and read your saved list adding each item to the list as you go.

Junday
June 4th, 2009, 05:58 PM
So it isn't possible with string (in My.Settings) ?

How would the code look example.

dglienna
June 4th, 2009, 07:55 PM
Not really. You'd have to save an ARRAY LIST of ITEMS, and then parse them by hand to load them. If you save them into a table, then you can bind to the table automatically.

Search around for the avenue to want to pursue. There are lots of examples on each method

DataMiser
June 4th, 2009, 07:59 PM
Junday

I did not say it wasn't possible to save in My.Settings but you are not dealing with a single text property here. You are dealing with any number of strings, 1 per list item. It is possible to read them in one by one and add them to a string with a seperator and then save that string doing the reverse to load them. It is possible to save each entry as a seperate string, It is possible to save them to a file of your choice, a database, registry or whatever you like but you need to loop through the list box to do so or at least you should. The only way that I am aware of that would not require looping through the list would be binding to a database and that has its own set of problems.