Link to home
Start Free TrialLog in
Avatar of geoffsweb
geoffsweb

asked on

VB.NET Windows Form retaining values on forms

VB.NET newbie here...
I have a 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. I am not Closing the form, just hiding it.  

Any help would be appreciated. Thanks in advance.
This is what I have on Form1, my main menu page:

Public Class frmForm1
Dim frmVS As New frmForm2


Private Sub btnForm2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForm2.Click

frmVS.Show()
Me.Hide()

End Sub


and then on Form2, I have a main menu button (to take me back to the main menu when they're done filling out data on the form... but maybe not completely done, so they don't want to save data yet)

Private Sub btnMainMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMainMenu.Click
Dim frm As New frmForm1
frm.Show()
Me.Hide()

End Sub

End Class

so if I fill out data on Form2, and then leave it there and click the MainMenu button, I go to the main menu... but then I need to click back to Form2 and still have the data previously entered there still there in the text boxes...

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ghayasurrehman
ghayasurrehman
Flag of Pakistan 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
Avatar of geoffsweb
geoffsweb

ASKER

Would this ToggleForm Sub go on every form them?  Where would it get called from?

Thanks!
Avatar of Mike Tomlinson
What version VB.net are you using?...
you sholuld have one main form which will be a MDI container and all other forms will be its child
I'm using Visual Studio 2008.

ghayasurrehman:  oops, I didn't set it up like that... every form is like the other form.... no parent/child relationship.  this is my first go around with a Windows Application.... I'm use to Web Applications.
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
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
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
Oooops, @Idle_Mind, I posted without refreshing the browser this time. :=)
OOOHHHHH, thanks, I'll try all this.... maybe I was looking at a VS 2003 example??!!!
Perhaps!  There is obviously more than one way to do it...I think the default instance approach is the easiest though.

Default instances were around in the old classic VB6 days but were left out of VB.Net 2002/2003.  There were brought back in VB.Net 2005 and I don't think are going anywhere!

C# programmers have to manually implement the singleton pattern on their forms to get a similar mechanism...