?
Solved

How to save and re-use listbox values?

Posted on 2006-11-01
5
Medium Priority
?
190 Views
Last Modified: 2010-04-23
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!
0
Comment
Question by:sasllc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
Jayadev Nair earned 1000 total points
ID: 17849268
Hi

"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."

This sounds like you are disposing (closing) the listboxForm and calling the other form. When you try to show back the same form you might be probably creating new instance of ListBoxForm which made you loose the Listbox values which were in the Old Form instance which already close.

'> You shows listbox form
ListBoxForm.Show

'> SHows another form
ListBoxForm.Close()   '> Here you loose values
OtherForm=New Form
OtherForm.Show

'> Again Go back to ListBox Form
ListBoxForm = New Form() '> This is new instance and donot have listbox values
ListBoxForm.Show()

So either you keep the ListBoxForm unclosed or keep the ListBox values globally.

Hope this helped you
Thanks.
0
 
LVL 9

Expert Comment

by:jrscherer
ID: 17849956
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
0
 
LVL 3

Author Comment

by:sasllc
ID: 17853998
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?
0
 
LVL 6

Expert Comment

by:Jayadev Nair
ID: 17857777
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
0
 
LVL 9

Assisted Solution

by:jrscherer
jrscherer earned 1000 total points
ID: 17857969
If you don't have any form open you could use as a host for a Public Shared string-array, then you probably need to write it on disk and retrieve it when you reload the form.
An easy way to do this safely is to serialize a class or structure containing the string array (SOAP or Binary) and write it in the FormClosing event and retrieve it in the Load event. Let me know if you need code snippets  Jack.net
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question