Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

 

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

Posted

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.

Posted (edited)

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

 

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.

Edited by shingo99
Posted

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:

mdiParentType tempParent = (mdiParentType)this.mdiParent;
tempParent.OpenOtherChild();

 

Hope that helps.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...