troubleshooting Question

Help with form dispose exception

Avatar of brettr
brettr asked on
C#
3 Comments1 Solution300 ViewsLast Modified:
I have an MDI application.  One form is opened.  From there a report button can be clicked, which opens another child form.  currentReportSelection contains the new'ed up frmReport.  I have a problem when frmReport is closed.  Once the report button is clicked again, a disposed exception occurs on the reportForm.Show() line:

private void btnReports_Click(object sender, EventArgs e)
{
    frmReport reportForm = currentReportSelection;
    buttonsDisable();
    reportForm.MdiParent = this.MdiParent;
    reportForm.WindowState = System.Windows.Forms.FormWindowState.Maximized;

    reportForm.Show();
}


The exception is:
Cannot access a disposed object.
Object name: 'frmReport'.

It always works fine on the first click but there after, I get the exception.  

How can I fix this?

Thanks,
Brett
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros