Link to home
Start Free TrialLog in
Avatar of sasllc
sasllcFlag for United States of America

asked on

How to save and re-use listbox values?

I need to understand how to best save listbox values when I leave a form, and later reload those values into the listbox when I go back into that form.  Note that my program is running in a CE environment, so I need to be careful with resources.

I have a text box (txtScanBale) where the user keys or scans in numbers, one at a time, and as he does, I save each entry in a listbox (lstBales), with the most recent entry at the top, using this code:

Me.lstBales.Items.Insert(0, Me.txtScanBale.Text)

If Me.lstBales.Items.Count > 200 Then

Me.lstBales.Items.RemoveAt(200)

End If

And, as shown, I limit it to the 200 most recent entries.  But when I leave the form, the listbox values all go away (as far as I know), because when I come back to the form, the listbox is empty.  

I'm wondering if there is an easy way to load these listbox entries into memory--maybe as an array??--either at the time I'm adding them to the listbox, or as I leave the form.  Or, maybe a way to save the listbox values themselves somehow, so they don't 'disappear' when I leave the form?  And then when I come back to this form, I need to be able to easily reload these entries into the listbox, in the same order they were in when I left the form.

If someone can give me a code example, or point me to a resource, it would be greatly appreciated!
ASKER CERTIFIED SOLUTION
Avatar of Jayadev Nair
Jayadev Nair
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You say "When I leave the form" What do you mean? Do you close the form? Or do you just activate another form, such as a Child form and come back later?
Please explain the workflow you use.
Jack.net
Avatar of sasllc

ASKER

Yes, I close the form, which I'm sure is why the listbox values are cleared from memory.

I do need to close the listbox form in my project.  So how do I 'keep the listbox values globally'?  Is there a code example for that somewhere?
Do you have any form that lives all the time app runs? Then declare in it or you can just declare
Public Shared values() as String in a module or in a live form and access it from wherever you want

Thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial