1

How do I update a property on a parent form from a child form in C#?

Joseph U.
  • 4,457
  • 10
  • 41
  • 47
  • I create the child utilizing: frm_AddEntry f_AddEntry = new frm_AddEntry(); f_AddEntry.Show(); – Joseph U. Nov 27 '10 at 18:58
  • What is it that says that f_AddEntry is a child of your parent form? – Örjan Jämte Nov 27 '10 at 19:00
  • You are correct, the from is not a child. It is another form in the application. I suppose my question should be how do I edit the properties of one form from another. – Joseph U. Nov 27 '10 at 19:26

5 Answers5

1

What I would do is create an event which the child control raises and the parent can then consume or not as needed.

Stephen Wrighton
  • 36,783
  • 6
  • 67
  • 86
0

Change the dataGridView1's 'Modifiers' property to Internal,

then you can access it using something like this ((frm01)this.Parent.Parent.Parent).dataGridView1

0
YourParentForm p = (YourParentForm)child.MdiParent;
p.YourProperty = "YourValue";
Örjan Jämte
  • 14,147
  • 1
  • 23
  • 23
  • This can be used if you have a MDIContainer as the parent form and that you set the MdiParent property when you create the child forms. – Örjan Jämte Nov 27 '10 at 19:01
0

If there is no parent child relation between the forms then you could have a look at the accepted answer to this SO question: https://stackoverflow.com/questions/4176682/access-of-public-method-between-forms/4176767#4176767

In this question it is about accessing a public method in an other form, so you could easily change that to a property.

Community
  • 1
  • 1
Örjan Jämte
  • 14,147
  • 1
  • 23
  • 23
0

//u can do it using a peroperty :

public static string update {
get{return textbox1.text} set{textbox1.text=value } }

Mohsen
  • 4,000
  • 8
  • 42
  • 73