在 Windows 窗体中刷新 DataGridView [英] Refresh DataGridView in Windows form
本文介绍了在 Windows 窗体中刷新 DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个表单,分别是表单 A 和表单 B.当我单击表单 B 上的保存按钮时,我希望刷新表单 A 的 DataGridView.
I have two forms let it be Form A and Form B. When I click save button on Form B I want the DataGridView of Form A to refresh.
我应该使用哪种方法?
推荐答案
使用事件是一种方法.下面是另一种更面向对象的方式.
Using a event is one way of doing this. Below is another way which is more object oriented.
在 FormA 中添加公共 Refresh 方法.
Add public Refresh method in FormA.
public void RefreshDataGrid()
{
//Do refresh
}
在构造FormB时将FormA的实例传递给FormB.您必须创建 FormB 构造函数来获取 FormA 实例.
Pass the instance of FormA to FormB when constructing FormB. You have to create FormB contructor to take FormA instance.
private FormA myFormA;
public FormB(FormA formA)
{
myFormA = formA;
}
现在您可以从 FormB 调用 FormA.ResfreshGrid() 方法.
Now you can call FormA.ResfreshGrid() method from FormB.
myFormA.RefreshGrid();
这篇关于在 Windows 窗体中刷新 DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文