关闭form2后,在form1中刷新DataGridView [英] Refreshing DataGridView in form1 after closing form2

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

问题描述

大家好,



我在form1中有DTG并且我使用SQLCommand在其中插入值。

当我点击按钮时在form2中保存(也关闭form2)我想刷新form1的datagridview。



有什么解决方案吗?

谢谢这么多。



Hello guys,

I have DTG in form1 and I'm inserting values in it using SQLCommand.
When I click button SAVE in form2(which also closes form2) I would like to refresh form1's datagridview.

Is there any solution?
THanks so much.

SqlCommand prikaz = new SqlCommand
                    ("INSERT INTO ..);
spojeni.Open();
                prikaz.ExecuteNonQuery();
                System.Data.DataTable dt = new System.Data.DataTable();
                System.Data.SqlClient.SqlDataAdapter SDA = new System.Data.SqlClient.SqlDataAdapter("...", spojeni);
                SDA.Fill(dt);

推荐答案

单击保存按钮后重新查询数据。
Requery the data after clicking the Save Button.


可能是这个帮助你

关闭form2时你调用form1的构造函数并编写逻辑来更新构造函数中的网格
May be this help you
While closing the form2 you call the Constructor of form1 and write the logic to update the grid in the constructor


好吧,
$ b在完成你在form2中插入数据的过程$ b后,你必须在页面加载事件上再次绑定form1网格,因为如果你没有绑定它或不刷新那个表单它应该看到旧记录,所以你必须在页面加载上编写代码进行绑定网格。



这肯定会解决你的问题:



http://stackoverflow.com/questions/7797975/how-to-refresh-a-form-from-another -form [ ^ ]



http://stackoverflow.com/questions/15896135/how-to-reload-form-in-c-sharp-什么时候按钮提交另一种形式点击



和如果解决问题,请接受解决方案并投票。
Well,
after you complete you process inserting data in form2 you have to bind form1 grid again on page load event because if you are not bind it or not refresh that form it should saw old record so you have to write code on page load for binding grid.

This will definitely solve you problem:

http://stackoverflow.com/questions/7797975/how-to-refresh-a-form-from-another-form[^]

http://stackoverflow.com/questions/15896135/how-to-reload-form-in-c-sharp-when-button-submit-in-another-form-is-click

And accept as solution and vote if solve your problem.


这篇关于关闭form2后,在form1中刷新DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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