0

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

1 Answers1

0

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.

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
  • How would save it to a database and would I be able to associate another string with each string in the string collection? Ie if I were to click on a string in the list box "John Smith" it would set a variable as "Johns_PC" and clicking on "Mary Smith" would set a variable as "Marys_PC". And this data needs to be added by the user somehow on the form. – user3462183 Mar 26 '14 at 02:30
  • You'd first have to decide what database to use, create the database and the table in it, then write some code to retrieve and save data. There's lots of information out there on those subjects. You should do some research, give it a go and then post a new question if you encounter a specific issue. You can use any database you want but I'd recommend SQL Server Express if the point is to learn about databases, otherwise perhaps SQL Server CE, Access or SQLite. – jmcilhinney Mar 26 '14 at 02:51