Question How do I save Listbox items in a My.Settings code?

Joined
May 3, 2009
Messages
5
Programming Experience
1-3
So, I have created this program and I want it to save the items that can be added into the list box with the My.Settings codes.
(So every time I open the program the items will be there)

Thanks so much! :)

I really need help!
 
The VS forums are for IDE issues, not language or code issues. Moved.

Add a StringCollection to your settings and then bind that to your ListBox via a BindingSource. To add a new item you add it to the StringCollection and call ResetBindings on the BindingSource. The contents of the collection will be automatically saved at shutdown and automatically loaded at startup.
 
The VS forums are for IDE issues, not language or code issues. Moved.

Add a StringCollection to your settings and then bind that to your ListBox via a BindingSource. To add a new item you add it to the StringCollection and call ResetBindings on the BindingSource. The contents of the collection will be automatically saved at shutdown and automatically loaded at startup.

Thanks sooo much! but, if you don't mind giving me a tutorial on this...sorry I'm not completely familiar with bindingsource's, and IDE. Thanks
 
Just add one to your form in the designer. Assign the collection to its DataSource property in code, then assign the BindingSource to the DataSource property of the ListBox.

The one gotcha is with the StringCollection in the settings. To actually create the collection you'll have to first add at least one item. You can then remove all the items to leave behind an empty collection if you want but, if you don't add an item, no collection will be created.
 
Just add one to your form in the designer. Assign the collection to its DataSource property in code, then assign the BindingSource to the DataSource property of the ListBox.

The one gotcha is with the StringCollection in the settings. To actually create the collection you'll have to first add at least one item. You can then remove all the items to leave behind an empty collection if you want but, if you don't add an item, no collection will be created.


could you please tell me how to do it with LISTVIEW item? with the code please? the thing is im using vb.net 2008 xpress and i added a predesigned explorer form and in that it has a listview not listbox and it doesnt have a property called bindingsource in its properties menu, shld it be in the code?
 
Just add one to your form in the designer. Assign the collection to its DataSource property in code, then assign the BindingSource to the DataSource property of the ListBox.

The one gotcha is with the StringCollection in the settings. To actually create the collection you'll have to first add at least one item. You can then remove all the items to leave behind an empty collection if you want but, if you don't add an item, no collection will be created.
ok even in a listbox, how to asign any source to a datasource? theres an option, add project data source...
 
Does it have to be a ListView? DataGridView or Listbox would be so much easier. See the attached project
 

Attachments

  • ArijitVBDNF.zip
    23.5 KB · Views: 86
Does it have to be a ListView? DataGridView or Listbox would be so much easier. See the attached project
i'm sorry but it has to be so because i inserted a pre designed form template in VB.NET 2008 and it has a listview and some code works only with that... but i'll try your project, thanks, i hope it's for vb 9.0 ?
 
Back
Top