This is a migrated thread and some comments may be shown as answers.

Cannot access parent

1 Answer 378 Views
Form
This is a migrated thread and some comments may be shown as answers.
Mohamed
Top achievements
Rank 1
Mohamed asked on 10 Feb 2014, 10:03 AM
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

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 12 Feb 2014, 04:44 PM
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).

Tags
Form
Asked by
Mohamed
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or