?
Solved

ObjectDisposedException

Posted on 2003-02-25
4
Medium Priority
?
369 Views
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".


Code:
void button1_Click(object sender,system.EventArgs e)
{
  try
  {  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.

regds
Rajesh
0
Comment
Question by:rnavduri
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Expert Comment

by:Volcano_88101
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
myform.Show();


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

0
 
LVL 4

Accepted Solution

by:
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.
0

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month9 days, 8 hours left to enroll

762 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