We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date


Hi. I currently have 2 forms. When they click a button in Form1, Form2 will appear containing a datagrid. If they double click a row in the grid, Form2 should close and the datagrid row will be transferred to Form1's textbox. My problem is, when I close Form2 and Form1 opens, it opens a new Form1. I want it retain the old Form1. I know it's because in Form2, I created a new instance of Form1. but if i take out the word new, it doesn't work! How do I open FOrm1 while retaining everything there without creating a new instance of the form? dim Form1 as new Form1() Form2.close() Form1.Show()

4 Replies

CB Clay Burch Syncfusion Team June 22, 2002 03:50 PM UTC

How did you get rid of Form1 when the double click occurred? Did you do a Form1.Close()? If so, try doing a Form1.Hide() instead. This should just hide the existing form, and provided Form1 is still in scope when you do the Form2.Close, you should just be able to Show it without creating a new instance.

AD Administrator Syncfusion Team June 23, 2002 08:05 AM UTC

Yes. I did close form1. But even if I hide Form1, it doesn't work. Here's my code. In Form1.. sub btnSearch_Click (...) dim Form2 as new Form2() Form2.Show Me.Hide end sub In Form2 sub dtgCustomers_DoubleClick (....) ' i have to declare this or else i get an error! dim Form1 as new Form1() Me.Close Form1.Show Form1.txtCustomer.Text = "..." end sub Even if I hide Form1 before calling Form2, when I call Form1 again from Form2, I still have to create a new instance. why? If I remove the "New" in my declaration, it says that "reference to a non-shared member requires an object reference!"

CB Clay Burch Syncfusion Team June 23, 2002 07:34 PM UTC

If Form1 is created first, make Form2 a member of Form1. Then in Form1's contructor or Load, create the instance of Form2 and Hide it. (Or, you could set it to Nothing and create it the first time you need it by testing to see if Form2 is Nothing. Then after that, don't create it again). After creating both forms, just call Hide and Show, only calling Close when you want to delete the object. With Form2 being a member of Form1, it will 'live' as long as Form1 is around, and you should not have to create it again. The point is that you cannot Dim Form2 inside Form1 and then close Form1, and expect to have Form2 still be around after you call Form2.Close.

VB Vipul Bhatt June 25, 2002 06:10 AM UTC

Hi why don't U try this sub dtgCustomers_DoubleClick (....) ''' i have to declare this or else i get an error! ''''''dim Form1 as new Form1() form1.Show() ''''your rest of the code

Live Chat Icon For mobile
Up arrow icon