Groups | Blog | Home
all groups > dotnet general > july 2005 >

dotnet general : Show a closed form brings up old values on form


Darren Murdoch
7/28/2005 6:37:39 PM
Gedday,
I have a program where users click on a Add Seeker option from the main menu
and then another form is opened and the users enter data and then it adds it
all to a dbase which works fine and then closes the form. The problem is
that when I close the form and go back to the main menu, if I choose to add
Seeker again and open the form it has retained the information in all the
boxes from what was typed in previously. If is dispose of the form and then
try to reopen it it tells me that I cannot access a disposed object. How can
I close a form and then reopen it so that everything is cleared.

Jeff Barnes
7/28/2005 9:45:48 PM
It sounds like you are always using the same instance of the form each
time it is displayed. When the menu item is selected, make sure you are
instantiating a new instance of the form.

[C#]
frmYourForm frm = new frmYourForm();
frm.Show();

I hope this helps.


Regards,

Jeff Barnes
Microsoft Certified Application Developer


[quoted text, click to view]
Darren Murdoch
7/28/2005 10:49:01 PM
Thanks for the rely. I tried what you said. The problem is that i have four
forms that they input information into and if at anytime they hit cancel i
want to be able to cancel or i support dispose of all the forms, so i had to
put a Public Dim myfrm as new frmshow in a module so that when i disposed the
forms they knew what i was talking about. Is this the best way to do it or
is there any easier way. Want i want to do is have the user to be able to
input information into these forms, if they cancel it unloads the forms and
if they go to add again if comes up with the first form empty instead of the
info they had previously typed in

thanks Darren

[quoted text, click to view]
Maqsood Ahmed
7/28/2005 11:31:25 PM
Hello,
You can try this if you are maintaining a single instance of the form

//Instance declaration.
YourForm form;

//In the event handler for the menu click
if(form == null || form.IsDisposed)
form = new YourForm
form.Show();

HTH. Cheers.
Maqsood Ahmed [MCP C#,SQL Server]
Kolachi Advanced Technologies
http://www.kolachi.net

AddThis Social Bookmark Button