Passing Data from a Mdi Child form to its Parent form
-
Okay i want to do this: Use the child's MDIParent property to get the parent form. Cast it to the MDI parent type. Then set/use the properties of the parent. What is the correct syntax because i keep getting Errors?
MyParent form = (MyParent)this.MDIParent;
However, if you need to pass data from the child to the parent based on a user action, it is better to do it with events. This way you avoid casting and you do not risk changes to the parent form or its' children. Search MSDN and you will get a good tutorial on establishing events. The altered data can be in your custom event arguments.
-
Okay i want to do this: Use the child's MDIParent property to get the parent form. Cast it to the MDI parent type. Then set/use the properties of the parent. What is the correct syntax because i keep getting Errors?
There are different approaches, but I think this will assist Code for the Closing event of the Child form i.e. on closing the form; here is the code: In this code the frmMain is the MDIParent of the frmItem, but casting is important in retrieving the properties of the parent form: private void frmItem_FormClosing(object sender, FormClosingEventArgs e) { Form f = sender as Form; ((frmMain)f).statusStrip = frmItem.statusStrip; }