Retaining data across multiple forms

geoffsweb

New member
Joined
Sep 8, 2010
Messages
1
Programming Experience
Beginner
VB.NET newbie here...
I have an vb.net windows application set up. It has multiple forms, about 6 in all. There's a main menu form, and then 5 other forms to collect data. The user will collect data on each form and bounce back and forth between forms. How do I get the forms to retain the data that has been entered into the text boxes and/or other controls on the forms? For example, they might fill out a few textboxes on a form, but then need to go to a different form and fill something out... and then back to the previous form. Right now, when they come back to the form, all the data previously entered in to the text boxes is gone. Any help would be appreciated. Thanks in advance.
 
you can define a class per form and then have the classes initialized in the main form. So form1 has a class called class1, form2 has class2 and so on. Use the reference to class1 in form1 and store any values in there - class1 is initialized in the main form and not in form1, form1 only uses it. when the user is done with form1 ans clicks the next button, show form2 that uses a reference to class2 and the same story. now if the user clicks the back button and goes to form1, you have class1 already initialized and some or all of its fields were set by the user before....so when you have to show form1 again (because the user came back to form1), you simply take the values form class1 and set to their appropriate controls on form1!

having the classes (class1, class2 and so on) in the main form lets you show/destroy a form as many times as needed and the classes would still be there in the main form! In other words, you sepearate the logic from forms

hope it makes sense
 
Back
Top