Calling mdichild method from other mdichild

M

Mickey Swanson

I have a MDI app wich has several different forms

I need to call a method on one MDIchild form from another child form.

I have a MDI form called frmMDI.
I have a mdichild form called frmMain.
I have a mdichild form called frmDetails.

after saving changes to frmDetails I need to update frmMain

I have a public method on frmMain to do this but I can't figure out how to
call this methos form frmDetails

any help

Mick
 
J

Jeffrey Tan[MSFT]

Hi Mickey,

Thanks for posting in this group.
Normally, when you create the child form in the parent form code, you
should store child form's reference in some fields, then you can call the
child form's method in parent form.
If you want to call parent form's method in child form, I think you need
find a way to pass parent form's reference to child form.
Normally, you'd better create an overrided constructor for child form which
takes a form refence parameter, then when you create the child form, you
can pass "this" pointer into child form's constructor to store it.

Code snippet like this:

//In Form1, create 2 child forms.
private Form2 f2;
private void frmMDI_Load(object sender, System.EventArgs e)
{
Form2 frmMain=new Form2();
f2=frmMain;//store Form2's reference in its private field f2, then you can
invoke Form2's method later.

Form3 frmDetails=new Form3(this);
}

//In Form3, create an overrided constructor which takes a Form reference as
parameter
private Form1 f;
public Form3(Form obj)
{
f=(frmMDI)obj;
//you already got a reference of parent form, then you can
invoke parent's method later
}

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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

Top