Issue with form hiding and showing

amthekkel

Member
Joined
Mar 26, 2009
Messages
14
Programming Experience
Beginner
hi,

I have a form e.g. Form1 , which displays a datagridview.
1) on form load, the datagridview doesnt have any data
2) the user clicks on a button called filter, this opens a form where the user can specify parameters to filter the data by
3) this form calls a setData() in Form1, which fills the dataset with the data

this works fine

if i click on a button called controlPanel it launches another form and hides this
e.g. dim cp as new ControlPanel()
this.hide()
cp.show()

On the controlpanel i have a button that links to form1. if i click on it

e.g dim frm as new Form1()
this.hide()
frm.show()

it redisplays Form1 but without any data in the datagridview.

I think the problem is that since i am creating a new instance for Form1 it comes up with the blank Form1. Is there a way to redisplay Form1 so that it retains the data that was displayed last, without having to retrieve the data from the database.

thanks in advance.

abhi
 
You are exactly correct as to why the problem occurs. Assuming Form1 is your startup form then the instance displayed is the default instance. As such, you can simply refer to that existing instance using the class name:
VB.NET:
Form1.Show()
Alternatively, you can have Form1 pass a reference to itself, i.e. Me (not 'this'), to the other form. The other form can then use that reference to access the Form1 instance that is hidden.
 
Back
Top