刷新其他表单datagridview [英] Refresh the other form datagridview

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

问题描述

我有两种形式。第一个是datagridview。我从第一个调用第二个。在关闭第二个表单更新第一个表单网格之后。 





我的尝试:



在第一次形式加载我放置,所以第一次它来了。在添加记录后我以第二种形式放置但错误即将来临。因为没有要刷新的datagridview。

解决方案

有两种方法可以做到这一点,具体取决于你打开第二种形式的方式。

1 )如果您使用ShowDialog打开Form2,则只需向Form2添加属性即可返回所需信息:

 Form2 f2 =  Form2(); 
if (f2.ShowDialog()== DialogResult.OK)
{
string valueFromTheOtherForm = f2.FirstValue;
...
myDataGridView.Rows.Add(valueFromTheOtherForm,...);
}



2)如果你用Show打开Form2那么它会变得有点复杂。同样,您需要一个属性,但这次您处理表单事件并获取数据。这应该有所帮助:在两个表格之间传递信息,第2部分:孩子到父母 [ ^


I have two forms. first one is datagridview. iam calling 2nd from first.after closing second form update first form grid. 



What I have tried:

in first form load i placed so first time it is coming. in second form after adding records i placed but error is coming. because there no datagridview to refresh.

解决方案

There are two ways to do this, depending on how you open the second form.
1) If you opened Form2 with ShowDialog, then just add properties to Form2 to return the information you need:

Form2 f2 = new Form2();
if (f2.ShowDialog() == DialogResult.OK)
   {
   string valueFromTheOtherForm = f2.FirstValue;
   ...
   myDataGridView.Rows.Add(valueFromTheOtherForm, ...);
   }


2) If you open Form2 with Show then it gets a bit more complex. Again, you need a property, but this time you handle form events and get the data. This should help: Transferring information between two forms, Part 2: Child to Parent[^]


这篇关于刷新其他表单datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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