Show a closed form brings up old values on form

G

Guest

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.

thanks
 
J

Jeff Barnes

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
 
G

Guest

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

Jeff Barnes said:
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


Darren said:
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.

thanks
 
M

Maqsood Ahmed

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top