Saving and Recalling items in a list box

I am working with visual basic 2005 express edition, and I have a form with a list box on, how would I save items in a list box when the form closes and recall them when the form opens.

Thanks



Answer this question

Saving and Recalling items in a list box

  • Timmy Dot Net

    Right ill go do that, thanks
  • PLF

    We'll go with XML
  • Roberto Icardi

    Well you have several options.
    The best one would be to save your list box items into a simple XML file.
    It should have a structure like this:

    <items>
    <item>
    <value>XYZ</value>
    <text>dada</text>
    </item>
    </items>

    Then when you close the form you simply write the XML file (Xml namespace) and when you load your form you read the XML and get all the items and add them to your list box.


  • slush_puppy

    Then have a look at the Xml namespace.
    There you will find everything you need for working with XML files.
    If you do a search on google, you will find many tutorials.


  • RichLeah

    I am only working with one list box with a unknown number of items as the user places in the items, how would I write the items to a file then recall them
  • jamvir

    You will first have to decide where do you wan't to store the items.
    Simple text file, XML, Configuration file, ...


  • Tako

    Or you could iterate throuth the items and write them to a simple ASCII file, Database or even a delimited String which you could write into a application setting which you could retrieve when you next open the form.

    Either way you'll need to write something to save and retrieve the data. A couple of questions which may determine where to store.

    How many Items are we talking in he listbox
    How many list boxes/forms are we looking


  • Saving and Recalling items in a list box