Cannot access parent

2 posts, 0 answers
  1. Mohamed
    Mohamed avatar
    1 posts
    Member since:
    Feb 2014

    Posted 10 Feb 2014 Link to this post

    Hello,
    I'm new to Rad controls and i'm having a problem accessing the parent radfrom of a child on (MDI not enabled). would appreciate the assistance.

    in the parent form when i click a button it does this:

    frmAddExtraItem fax = new frmAddExtraItem();

    fax.Show(this);

    and it shows the child form, but when i click a button in the child form the code is this:

    ((MainForm)this.ParentForm).dataGridView1.Rows.Add(insertitem.EDescription);


    now datagridview1 is public, but this.ParentForm is always null, i tried all combinations possible for both code snippets, trying this.Parent, and even this.Parent.Parent multiple times, and also in the first code i tried fax.ParentForm = this, fax.Parent = this, and fax.Parent = this.Parent, and so on many combinations including fax.ShowDialog(), but nothing seems to work and i always get this.Parent or this.ParentForm as null, how can i access the dtatagridview1 in the parent in that case?

    thank you
  2. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 12 Feb 2014 Link to this post

    Hi Mohamed,

    Your question has already been answered in the other thread you've opened. 

    I am adding the answer here in order the community to benefit from it:

    You can use the Owner property to get the corresponding grid:
    private void radButton1_Click(object sender, EventArgs e)
    {
        RadGridView grid = ((Form1)this.Owner).RadGridView1;
        grid.Rows.AddNew();
    }

    I hope this helps. 

    Regards,
    Dimitar
    Telerik

    Check out the new Telerik Platform - the only modular platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native apps. Register for the free online keynote and webinar to learn more about the Platform on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT).

  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top