Click here to Skip to main content
14,579,188 members
Rate this:
Please Sign up or sign in to vote.
See more:
i got my listbox (listBox1)
i want to save the items inside and load them when form1 is loaded

i've got no idea so please explain everything you can
Thanks

What I have tried:

i treid looking for this in the internet , i found nothing
some posts saying that making a .txt file is better but i don't like it
Posted
Updated 28-Jun-20 22:52pm
Rate this:
Please Sign up or sign in to vote.

Solution 1

Top be honest, they "use a file" faction is probably right - settings files aren't really there for data and they aren't really good at it.

Using a file isn't difficult, and particularly with something like a list box it is the logical way to do it. It's even pretty easy, File.ReadAllLines will return each string separately in an array for you ready to load into your listbox, and File.WriteAllLines will save them back for you ready for next time if they get changed.

This will show you a good place to store the file: Where should I store my data[^]
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Every .net application has got a configuration file: app.config already. If you don't see it, you can add it! See: How to add an app.config file to a project - Visual Studio | Microsoft Docs[^]

Please, read this article on CP KnowledgeBase: Read/Write App.Config File with .NET 2.0[^]

You can also use custom file:
- text file (*.txt, *.csv),
- xml file (*.xml),
- database file (*.mdb, *.db)
All you need to do is to provide methods to read/write proper data.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100