以另一种形式刷新网格 [英] Refresh Grid in another form

查看:106
本文介绍了以另一种形式刷新网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我有一个有两种表格的申请表。



主窗体包含2个标签,一个网格(填充List< class>中的数据)和一些复选框以选择数据过滤器。



第二种形式(名为OverheadWin)包含相同的2个标签,网格填充相同的数据。它的目的只是为了在扩展显示器上显示最大化信息。



应用程序运行良好但我发现更新第二种形式的唯一方法是关闭和重新打开它。



我想找到一种更方便的方法来刷新主表单中第二种形式的信息,但到目前为止我尝试过的所有解决方案(像ohdWin.Reresh())不起作用。



我也尝试过第二种形式的后台工作者定期更新数据,但我没有成功(也许我做错了什么)。我的试验结果是冻结的第二种形式(有一个应该工作的位移条),或刚刚打开后关闭的窗口(第二种形式的主要方法只运行一次,窗口关闭一次到达此方法结束)。



第一个表格的当前代码是

Hallo,

I have an application with two forms.

The main form contains 2 labels, one grid (filled with data from a List<class>) and some checkbox to select filters on the data.

The second form (named OverheadWin) contains the same 2 labels and the grid filled with the same data. Its purpose is only to show the information maximized on an extended monitor.

The application works well but the only method that I found to update the second form is closing and reopening it.

I would like to find a more convenient way to refresh the information in the second form from the main form, but so far all the solutions that I tried (like ohdWin.Reresh()) do not work.

I have also tryed with a background worker in the second form that periodically updates the data, but I did not succeed (maybe I do something wrong). The results of my trials were the second form freezed (there is a displacement bar that should work), or the window closing just after opening (the main mehtod of that second form runs only once and the window closes once reached the end of this method).

The current code of the first form is

public partial class MainWin : Form
{
    OverheadWin ohdWin;
...


private void OpenOhdWin()
{
    ohdWin = new OverheadWin();
    ohdWin.Show();
}





更新部分,待改进



The update part, to be improved

ohdWin.Close();
OpenOhdWin();





第二种形式的主要方法:( OhdGridShow显示标签和网格中的数据)



The main method of the second form: (OhdGridShow shows the data in the label and the grids)

public partial class OverheadWin : Form
{
    public OverheadWin()    
    {
        InitializeComponent();
        OhdGridShow();
    }





欢迎任何想法。



提前谢谢,

David



Any idea will be welcome.

Thank you in Advance,
David

推荐答案

表格2内: -



创建一个名为RefreshGrid的公共函数名。



Public void RefreshGrid()

{

DataGridViewObject .DataSource = null;

DataGridViewObject.DataSource = dataTable;

}



添加数据后调用此函数从形式2的现有对象的第一个表单。



希望你可以尝试这个。
Inside Form 2:--

Create a public function name say RefreshGrid.

Public void RefreshGrid()
{
DataGridViewObject.DataSource = null;
DataGridViewObject.DataSource = dataTable;
}

Call This Function after adding data from first form with the existing object of form2.

Hope you can try this.


这篇关于以另一种形式刷新网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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