Click to See Complete Forum and Search --> : MDI parent on child's child form


Innocent
November 26th, 2002, 05:53 PM
I have a MDI parent window and two child windows (for this example - the app contains lots of forms...).

In frmMDIParent the child form is made visible:


Public Sub OpenChild()
Dim dlgChild as frmChild = New Child
dlgChild.MdiParent = Me
dlgChild.Show()
End Sub


In frmChild I try to open form with the parent of child as parent:


Public Sub OpenChild2
Dim dlgChild2 as frmChild2 = New frmChild2
dlgChild2.MdiParent = Me.Parent 'Application crash here
dlgChild2.Show
End Sub


Anyone knows how I can solve this?

Athley
November 27th, 2002, 02:12 AM
Hmm, I wonder what makes the application crash, the code is quite correct. It even worked as I just tested it.

Do you get an error at least?

/Leyan

Innocent
November 27th, 2002, 07:08 AM
The message I get is:

"An unhandled exception of type 'System.InvalidCastException' occured in App.Exe"

(I have yet to implement proper error handling...)

Athley
November 27th, 2002, 08:58 AM
Oooops.... I missed a thing here.

You are trying to use a property that is not a member of the Me object, Parent. Change....

dlgChild2.MdiParent = Me.Parent

to

dlgChild2.MdiParent = Me.ParentForm

....instead.

/Leyan

Innocent
November 27th, 2002, 09:40 AM
Me.Parent does exists in quick listing...
Me.ParentForm does also exist - and works...

Thanks alot! :)

Athley
November 27th, 2002, 09:59 AM
You're welcome.... funny, it didn't occur in my listing, maybe you have done some inheritance work...

/Leyan