locked
Retrieve control value from parent form from a user control RRS feed

  • Question

  • Hi,

     

    I have a user control on a parent form. The parent form has a RadioButton. I need to be able to determine the checked state of the RadioButton from the user control.

     

    I tried creating a public property on the parent form with the following code:

     

    public bool IsDemarcateMode

    {

    get { return rdoDemarcate.Checked; }

    }

     

    However, it does not work because the property is not visible from the user control at run time, using the following line of code:

     

    bool bChecked = this.Parent.IsDemarcateMode;

     

    Any suggestions?

     

    Thanks.

    Dan

    Wednesday, October 29, 2008 1:30 AM

Answers

  • That did it!  Thanks. The exact syntax was not immediately obvious, but here is what worked:

     

    frmMain frm = (frmMain)this.Parent;

    bool bChecked = frm.IsDemarcateMode;

     

     

    Wednesday, October 29, 2008 12:50 PM

All replies

  • You need to cast the "this.Parent" to your parent form in order to get that property from your parent form.

    Wednesday, October 29, 2008 5:49 AM
  • That did it!  Thanks. The exact syntax was not immediately obvious, but here is what worked:

     

    frmMain frm = (frmMain)this.Parent;

    bool bChecked = frm.IsDemarcateMode;

     

     

    Wednesday, October 29, 2008 12:50 PM