MDIparent and show form problem




I open a child form with a menubutton in the parentform -> no problem
2nd: Open a second child form with a button on the first child form -> no
3rd: Open the first child form in the Closed Event from the second child
form -> still no problem
4th: Now the problem raises: When I open again the second form with the
button on the first child form an Error occurs which say's:
An unhandled exception of type 'System.ObjectDisposedException' occurred in
Additional information: Cannot access a disposed object named

What could this be?

Thanks for your help.


Worked out code in order of mentioned steps above:

Declared in module :
Public frmParent As New Form1 'MDI Parent
Public frmProjectOpen As New frmProjectDataOpen 'Child1
Public frmEdit As New frmProjectEdit 'Child2

Openening first child form with:

frmProjectOpen.MdiParent = Me

Openening 2nd child form with button on first child form:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
frmEdit.MdiParent = Me.MdiParent
End Sub

Back to first child with 2nd child Closed Event:

Private Sub frmProjectEdit_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed

frmProjectOpen.MdiParent = Me.MdiParent

End Sub



Andrew Smith \(Infragistics\)

When a modeless opened form is closed, it is automatically disposed. So your
member variable - frmEdit - is a reference to a disposed form once you have
closed that instance of the form (the same goes for frmProjectOpen). If you
actually need to use the same instance of the form, you'll need to cancel
the closing and hide the form - of course that will likely lead to some
problems when closing the mdiparent since all mdi children must be closed
first and if you cancel closing the child, the parent will not be closed.
Perhaps you should just create a new instance of the child form and not try
to maintain member variables to them (or clear the member variable when the
form is closed and recreate it when showing about to show a new instance of
the form).


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