如何在C#Windows应用程序中刷新主窗体 [英] How to refresh Main Form in C# Windows Application

查看:219
本文介绍了如何在C#Windows应用程序中刷新主窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从另一个表单中关闭并刷新主表单中的子表单。





谢谢,

ttds

How to close and refresh the child form within Main Form from another form.


thanks,
ttds

推荐答案

在我的项目中,我遇到了以下情况,我认为这可能有助于您获得所需的解决方案



父表单包含显示所有员工数据的网格和名为添加新员工的按钮。单击添加按钮单击,将打开子表单,我们可以在其中添加新的员工详细信息,单击保存按钮时,数据应保存在数据库中,并且子表单将关闭。

同时保存的员工数据应反映在父页面中的数据网格中。



父母表格:

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);
   frm2.Show();
 }

 private void frm2_FormClosed(object sender, FormClosedEventArgs e)
 {
   DataTable dt = new DataTable();
   //get Eployee data from db and fill it dt;
   dgvTesting.DataSource =  dt;
   this.Close();
 }


在您保存新条目后,您所遗漏的只是重新加载员工列表。应该是直截了当但如果不是,我会帮助你没问题。
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.


这篇关于如何在C#Windows应用程序中刷新主窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆