|
-
Nov 14th, 2005, 04:05 AM
#1
Thread Starter
Junior Member
saving 3 listboxes and retrieve it back!!
i have 3 listboxes that link to each other.
example:
Listbox1
Mark
Luke
Alban
Listbox2
4160
5480
6789
Listbox3
May
June
October
how do i save all these 3 listboxes in one textfile and retrieve it back to their own listbox that they belongs to.
Please Helppp..its kinda urgent!!
-
Nov 14th, 2005, 04:16 AM
#2
Re: saving 3 listboxes and retrieve it back!!
Well, that's easy if your data will always relate to each other like that, however that's not very good use of ListBoxes.
All you really need is a for statement, and to use the IO.StreamWriter method to write the data to text files.
VB Code:
Dim sw as IO.StreamWriter("Myfile.txt")
For i as Integer = 0 to Listbox1.Items.Count
sw.WriteLine(Listbox11.Items(0).Text)
...'etc, etc...
Next i
sw.Close();
Or, use XML and config files to do the trick. A quick MSDN Search for config and XML will guide you in the right direction.
Bill
-
Nov 14th, 2005, 09:25 PM
#3
Re: saving 3 listboxes and retrieve it back!!
Or for all three....
VB Code:
For i as Integer = 0 to Listbox1.Items.Count
sw.WriteLine(Listbox1.Items(i) & "," & Listbox2.Items(i) & "," & Listbox3.Items(i))
Next i
That would save each index of the three boxes into one line, seperated by commas.. then you would use streamreader to read the lines in, and use strings.split to split on the comma delimter.. then use index 0 of the resulting array into listbox1, index 1 to listbox2, and index 2 to listbox3
Last edited by gigemboy; Nov 15th, 2005 at 01:26 AM.
-
Nov 15th, 2005, 01:24 AM
#4
Re: saving 3 listboxes and retrieve it back!!
A ListBox is supposed to allow the user to make a choice from a list. Are you allowing the user to select a name, a number and a month, or is the first item in each list related, the second item in each list related and the third item related? If it's the second case then three LixtBoxes is the wrong choice. You should use either a DataGrid or, more likely in this case, a ListView.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|