How to Access MDI Parent Forms From MDI Child Form

How to access MDI Parent forms from MDI Child forms:This code shows how to access objects contained in an MDI parent form, from an MDI Child form.Simply using MDIParent will not work, you have to cast MDIParent to your MDI Parent forms. Here isthe code:

//In the MDIChild Form

private void btnAddToTree_Click(object sender, System.EventArgs e)
{

//Cast MDIParent to your MDIParent Form
theMDIParentForm theParent = (theMDIParentForm) this.MDIParent;

//Now you can access objects on the MDI Parent form from MDI Children
theParent.myTreeViewControl.Nodes[0].Add(new TreeNode("New Child Node"));

}

Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!