Results 1 to 4 of 4

Thread: saving 3 listboxes and retrieve it back!!

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Posts
    29

    Unhappy 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!!

  2. #2
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    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:
    1. Dim sw as IO.StreamWriter("Myfile.txt")
    2. For i as Integer = 0 to Listbox1.Items.Count
    3.   sw.WriteLine(Listbox11.Items(0).Text)
    4.   ...'etc, etc...
    5. Next i
    6. 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
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  3. #3
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: saving 3 listboxes and retrieve it back!!

    Or for all three....
    VB Code:
    1. For i as Integer = 0 to Listbox1.Items.Count
    2.   sw.WriteLine(Listbox1.Items(i) & "," & Listbox2.Items(i) & "," & Listbox3.Items(i))
    3. 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.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width