Click here to Skip to main content
15,796,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to close and refresh the child form within Main Form from another form.

Sergey Alexandrovich Kryukov 5-Mar-13 22:55pm    
First of all, there is no a "child form" (I don't mean MDI which is best avoided). Forms are not children of the main one.
If you close something, why refreshing? Generally, forms do not need refresh. If you think you need it, chances are, you are doing something wrong. What?

In my project I faced following scenario which i think that may help you to get the solution which you want

Parent Form Contains Grid that displays all Employee data and button Called "Add New Employee". On Add button Click, a Child form is opening, where we can add a new Employee details, and on save button click, data should be saved in database and child form is closed.
At the same time the saved employee data should reflect in the datagrid which is there in parent page.

On Parent Form :
 private void btnAdd_Click(object sender, EventArgs e)
   frmChildForm frm2 = new frmChildForm();
   frm2.FormClosed + = new FormClosedEventHandler(frm2_FormClosed);

 private void frm2_FormClosed(object sender, FormClosedEventArgs e)
   DataTable dt = new DataTable();
   //get Eployee data from db and fill it dt;
   dgvTesting.DataSource =  dt;
Share this answer
ttds 6-Mar-13 2:28am    
thanks for your help, it is almost the same what I want but
When click the Employee menu on Parent Form , then display the lists of Employee data on (Child Form used usercontrol form) within Parent Form. Then, button Called "Add New Employee" on Child Form within Parent Form. then Next steps is the same of yours.

So I need to refresh the list data of the child form.
If you have any idea more. Please help me.
By the sounds of it all you are missing is re-loading the list of employees after you save the new entry. Should be straight forward but if not i will help you out no problem.
Share this answer
tiagu 10-Feb-16 8:41am    
Just to say THANK YOU!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900