|
-
Apr 10th, 2013, 12:48 PM
#1
Thread Starter
Member
[RESOLVED] Close / Hide / Dispose A Form Issue
Hello all
I have a little issue.
I have two forms in my app (Form1 & Form2)
when the button to show form2 is clicked and form2 is loaded an operation is performed.
if form2 is closed/hide and then reopend I want the "form_load" function to execute but this does not seem to be the case.
I tried this
(from form2)
Form1.show()
me.dispose
but this throws and exception on the windows PC.
All I want to do is have form2 refreshed/reloaded anytime it is called?
Help?
-
Apr 10th, 2013, 01:09 PM
#2
Frenzied Member
Re: Close / Hide / Dispose A Form Issue
Try Me.Hide() instead of dispose
-
Apr 10th, 2013, 02:39 PM
#3
Re: Close / Hide / Dispose A Form Issue
It still won't trigger the Load event.
You will only get the load event when the form loads for the first time. Your example has me a bit baffled, since I don't understand the order. If you had Form1 show Form2, and when you were done with Form2 you closed it, then created a new instance of Form2 and displayed it, you'd get the Load event to run. However, you would also be showing a totally new instance, which may not be what you want if you want the form to reappear the way you left it. If you aren't willing to create a new instance of Form2 each time you want to show it, then you'll want to move the activity out of Form Load and into something else. The VisibleChanged event seems like the only one that works well for this, though Activated may be what you want in some situations.
My usual boring signature: Nothing
 
-
Apr 10th, 2013, 03:00 PM
#4
Re: Close / Hide / Dispose A Form Issue
I'm willing to bet my right eye he is using the default instance.
 Originally Posted by gmack
All I want to do is have form2 refreshed/reloaded anytime it is called?
Then create a new instance of the Form every time you want it as Shaggy suggested.
-
Apr 10th, 2013, 03:01 PM
#5
Thread Starter
Member
Re: Close / Hide / Dispose A Form Issue
Ok that makes sense... Thanks for the input.
-
Apr 11th, 2013, 01:24 PM
#6
Thread Starter
Member
Re: [RESOLVED] Close / Hide / Dispose A Form Issue
Ok I thought I had solved this but NOPE.
I still have the issue with closing/opening a form.
I have a windows form (lets call it Form2) that i open from form1.
Form2 has a DGV and does some caluculations and such from the DGV rows etc.
when i open form2 from form1, for the first time, form2 works fine.
when i close form2 (me.close or me.hide) then from form1 reopen form2 i receive errors from my DGV.
It seems that somehow It is not reinitializing (if thats the right term) the form2.
I have tried this to open form2
dim myform2 as new form2
myform2.open()
HELP?
-
Apr 11th, 2013, 01:26 PM
#7
Re: [RESOLVED] Close / Hide / Dispose A Form Issue
-
Apr 11th, 2013, 01:32 PM
#8
Thread Starter
Member
Re: [RESOLVED] Close / Hide / Dispose A Form Issue
The error is an "index out of range" error happening when I add columns to the DGV and change the values in the cells.
it seems as if form2 has allready loaded and its trying to compound my DGV calc & adds, even though I disposed of it.
If i just hide it, then if the user changes values in form1 when form2 is re opened , it does not recalculate.
argh....
-
Apr 11th, 2013, 02:05 PM
#9
Thread Starter
Member
Re: [RESOLVED] Close / Hide / Dispose A Form Issue
So, I gave UP.
instead I added a "REFRESH" button the form2 to refresh the DGV. if a user changes data in form1 then a flag is set & the refresh button(on form2) is enabled. now i only Hide form2 when user closes....
-
Apr 11th, 2013, 02:19 PM
#10
Re: [RESOLVED] Close / Hide / Dispose A Form Issue
Is this Form opened using ShowDialog by any chance ?
-
Apr 11th, 2013, 02:21 PM
#11
Thread Starter
Member
Re: [RESOLVED] Close / Hide / Dispose A Form Issue
 Originally Posted by Niya
Is this Form opened using ShowDialog by any chance ?
no, I have never used that? what does it do?
-
Apr 11th, 2013, 02:24 PM
#12
Re: [RESOLVED] Close / Hide / Dispose A Form Issue
Well never mind. Closing a form opened by ShowDialog doesn't dispose of it. That's why I asked. Come to think of it, if you did what I told you to do, which is to create a new instance every time, you should have a problem with Form's old state clashing with the your attempts to initialize it.
-
Apr 11th, 2013, 02:27 PM
#13
Thread Starter
Member
Re: [RESOLVED] Close / Hide / Dispose A Form Issue
 Originally Posted by Niya
Well never mind. Closing a form opened by ShowDialog doesn't dispose of it. That's why I asked. Come to think of it, if you did what I told you to do, which is to create a new instance every time, you should have a problem with Form's old state clashing with the your attempts to initialize it.
Well I sure tried that
DIM myForm as New Form2()
Myform.show
-
Apr 11th, 2013, 02:30 PM
#14
Re: [RESOLVED] Close / Hide / Dispose A Form Issue
Ok....are you doing that every time you open the Form ? Make sure now. Go and check your code and make sure there isn;t any place where you're just calling Myform.Show without setting Myform to a new instance.
-
Apr 11th, 2013, 03:03 PM
#15
Re: [RESOLVED] Close / Hide / Dispose A Form Issue
Ultimately, it comes down to this:
When you create a new instance of the form, you are creating a new object. It won't be retaining any values from any other instance unless you made them Shared (in which case, all the instances share a single copy of that item). You certainly didn't make the DGV shared, and it doesn't seem likely that you made anything else shared without some good reason. Therefore, if, when you call that MyForm.Show, you should be going through the load event, and everything should be in its initial state because MyForm is a new object. You can see what is happening by putting a breakpoint on MyForm.Show and stepping forwards to see what happens. If the DGV is not in its initial state, then you have managed to entangle them in some way that you haven't told us about. Of course, you probably didn't tell us because you didn't realize you had done it, but that is what you are looking for.
My usual boring signature: Nothing
 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|