Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium



Posted on 2003-02-25
Medium Priority
Last Modified: 2008-02-01
When I am calling Form2 from From1 by clicking the button, first time it is showing the data. Next time when I click the button, its throwing the following error..

Caught: Cannot access a disposed object named "Form2".
Object name: "Form2".

void button1_Click(object sender,system.EventArgs e)
  {  form2.Show();
  }catch (ObjectDisposedException err)
   {Console.WriteLine("Caught: {0}", err.Message);}

I have tried the ShowDialog method also. In that case it is appending the same data again.

When I click the button from Form1, it shows 4 records in Form2 (in datagrid). When I click it again it appends the same records. so I see 8 records.

Pl suggest.

Question by:rnavduri

Expert Comment

ID: 8022425
What is the Definition of Form2?
Is Form2 the name of your Form?
If you are probably want to define your variable something like this

private Form2 myform = new Form2();

in your Form1 class
Then whenever you call your ShowCode go

Also on another note.
You might change the OnClosing and have it autohide on the user hitting the okay button or hitting the Close button


Accepted Solution

Nebulus_ earned 200 total points
ID: 8024423
from .NET Framework Class Library:

Note:   When the Close method is called on a Form displayed as a modeless window, you cannot call the Show method to make the form visible, because the form's resources have already been released. To hide a form and then make it visible, use the Control.Hide method.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question