我有一个带有datagridview的表单。

当您双击datagridview中的一行时,将打开另一个表单,该表单基本上是一个表单,您可以在其中编辑双击的数据。

此“编辑”表单中有3个按钮,即删除,更新和返回主表单按钮。

完成您应该在此表单上执行的操作后,它将关闭。

我的问题是;

当此表单关闭时,我希望刷新主表单中datagridview内部的数据,如何从编辑表单中调用主表单上的该函数。

请记住,我已经有了一个重载函数,我们称其为refreshData();。

最佳答案

如果使用了.ShowDialog(),则只需将刷新功能放在此代码行下。

该程序将继续

private void cell1_DoubleClick(object sender, System.EventArgs e)


功能。

因此,您的代码看起来与此类似。

private void cell1_DoubleClick(object sender, System.EventArgs e)
{
     //Your previous code ....

     //The part where you open the EditForm
     MyEditForm.ShowDialog();

     //After it has been closed the program will continue to execute this function(if it has not been ended yet)
     RefreshData();
     //Since this function is running from your main form, the function RefreshData() will be executed on your main form aswell
}


完全不需要检查某些对话框结果。

10-07 19:19
查看更多