Accessing parent form from child from
-
Please feel free to correct any terminoligy mistakes. From the main form 'frmMain' a child form 'frmChild' is instantiated and displayed. When 'frmChild' has focus and user is interacting, I need to cause a change on the parent form 'frmMain'. How do I get to cbOptionA (a checkbox) in frmMain? frmMain.cbOptionA.Checked = true; obviously wont work as that is the name of the class. Anyone care to school me? Thanks.
-
Please feel free to correct any terminoligy mistakes. From the main form 'frmMain' a child form 'frmChild' is instantiated and displayed. When 'frmChild' has focus and user is interacting, I need to cause a change on the parent form 'frmMain'. How do I get to cbOptionA (a checkbox) in frmMain? frmMain.cbOptionA.Checked = true; obviously wont work as that is the name of the class. Anyone care to school me? Thanks.
You can do this by two ways: 1. If there is any event in the child form, due to which the check box in main form should get checked, use a delegate and handle it in the main form itself. Now within that event, you can check your checkbox. 2. Have a public static property for the checked property of your checkbox, say
OptionAChecked
in your main form. Now, from the child form you can access that property and set it to true. You can access the property from the child without worrying about the instance. ie if the name of your main form class isMainform
, you can useMainForm.OptionAChecked
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
-
You can do this by two ways: 1. If there is any event in the child form, due to which the check box in main form should get checked, use a delegate and handle it in the main form itself. Now within that event, you can check your checkbox. 2. Have a public static property for the checked property of your checkbox, say
OptionAChecked
in your main form. Now, from the child form you can access that property and set it to true. You can access the property from the child without worrying about the instance. ie if the name of your main form class isMainform
, you can useMainForm.OptionAChecked
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
-
Using suggestion 2, once the property has been changed by child in MainForm, how do I get MainForm to act upon that change? THank you
If you have handled the
CheckChanged
event for the checkbox, it will fire when you change the checked state of your checkbox. If not, then you can handle it to get some work done.50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
-
If you have handled the
CheckChanged
event for the checkbox, it will fire when you change the checked state of your checkbox. If not, then you can handle it to get some work done.50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!