mdi child problem

shingo99

Freshman
Joined
Jul 19, 2004
Messages
31
hi
i use vb.net to make a simple data showing application
i have make 3 forms
1 mdi parent n 2 child
it is simple for a parent form to call a child form
but how to code a child to call another child form to show up at the parent form
if parent form call child would be like this

Code:
frm.MDIParent= ME
frm.show

here is to make things more understanding
form1(parent) calls form2(child)
form2(child) calls form3(child)
note....form2 and form3 must be in form1(parent)
all this happen on button clicking
how to do this?
thank you in advance
 
You could expose public methods in the mdiParent that are used to open your child forms. Then, from child A, issue a call into the mdiParent to open child B.

In child A, you'll probably have to cast "this.mdiParent" to a variable of type-of your actual mdiParent class (we'll call it "Daddy") - then call DaddyInstance.OpenChildB(), or whatever.
 
In child A, you'll probably have to cast "this.mdiParent" to a variable of type-of your actual mdiParent class (we'll call it "Daddy") - then call DaddyInstance.OpenChildB(), or whatever.
i dont quite understand this part
here is what i done after reading this reply
declare a public sub in parent form
make the button in child A to call that sub so that child B can be shown
child A button i type as
Main.CallB
and the sub is like below

Code:
Public Sub CallB
Dim frm as New FormB
frm.MdiParent= Me
frm.show
End Sub
am i doing the right thing?
coz this error show up after i press the button
An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication7.exe

Additional information: Object reference not set to an instance of an object.
 
Last edited:
Oh yeah, when you instantiate your child forms, for this to work, you need to pass a reference of the mdiParent down to the child and set that as the mdiParent in your child classes in the constructors.

Then, when you need to open the other windows, you'll have to do something like:
Code:
mdiParentType tempParent = (mdiParentType)this.mdiParent;
tempParent.OpenOtherChild();

Hope that helps.
 
Back
Top