在Windows窗体刷新的DataGridView [英] Refresh DataGridView in Windows form

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

问题描述

我有两种形式让它成为A型和B,当我点击保存按钮表BI希望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.

在形式上加入公共Refresh方法。

Add public Refresh method in FormA.

public void RefreshDataGrid()     
{       
   //Do refresh    
}

传递备考的实例构造FormB时FormB。你必须创建FormB构造器采取形式上的实例。

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屋!

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