How can I add data to a list box that is still there when I open my program again? (Visual Basic)

StackOverflow https://stackoverflow.com/questions/22649698

  •  21-06-2023
  •  | 
  •  

Question

I am currently working on a LAN messaging application in visual basic .net that works through sending a shutdown notification then aborting the shutdown, and I am trying to implement in a contacts feature that displays the computer's name when the user clicks on someone's name in a listbox or something similar, but I am stuck. I am trying to allow the user to add people and their computer's name to the listbox through a dialog, and make it stay there permanently, but i have no idea how to start. is there a way to do this through a database?

thanks

Was it helpful?

Solution

The ListBox is basically irrelevant. If you want to persist data between sessions then you have to save it to some external store, e.g. a file or database.

If all you want is a list of Strings then the simplest option may be to add a StringCollection on the Settings page of the project properties. The contents of that collection will be automatically saved to the application config file at shutdown and automatically loaded at startup. You can populate the ListBox from that collection at startup and then populate the collection from the ListBox at shutdown.

Note that, in code, you access application settings via My.Settings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top