将值从窗体传递到另一个Windows窗体的datagridview [英] pass a Value from a Form to datagridview of another windows form

查看:86
本文介绍了将值从窗体传递到另一个Windows窗体的datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有两种形式form1和form2. Form1包含DataGridView控件,Form2包含4个文本框和1个保存按钮.我的问题是,如果我在Form2的所有文本框中输入了任何数据,然后单击保存"按钮,则只有Form1 DataGridView应该打开,并且应该检索新输入的和现有的数据.请用示例答复我.

解决方案

在将值保存为form1后将保存按钮单击事件打开为

Form1 form1 = new Form1();
form1.Show();



加载事件时绑定datagridview.
就像您说过的那样,您正在第一页中插入数据,所以我想您不是根据时间来保存数据,必须将其保存在存储器中以便进一步检索.

如果数据存储一次,那么您只需打开一个包含datagridview的页面来显示那些保存的数据,这是一个简单的任务.

当您使用ASP.Net时,Response.Redirect("Page.aspx")可以为您提供帮助;如果您使用WinForms,则

Form2 form = new Form2();
form.show();



您可以通过保存按钮在数据插入完成后立即附加上面的代码.


您必须使用Property或public变量来累加Form2.更改后,输入或单击保存"按钮,则应使Form2的事件更改DataGridView的数据源并重新绑定.


hi all,

i''ve two forms form1 and form2. Form1 contains DataGridView control and Form2 contains 4 Text Boxes and 1 save button. my question is if i entered any data in all text boxes in Form2 and click on save button, only Form1 DataGridView should open and should retrieve new entered and existing data. please reply me with an example

解决方案

On save button click event after the saving the values open form1 as

Form1 form1 = new Form1();
form1.Show();



on load event bind the datagridview.


Your presentation tag can give us better understanding of the scenario.

As of you''ve said, You''re inserting data in first page so I suppose that you''re not keeping data on temperory basis you must be keeping it in storage for further retrieval.

If data is stored once then it''s just a simple task for you to just open a page consisting datagridview for displaying those saved data.

As of you''re using ASP.Net then Response.Redirect("Page.aspx") can help you and if you''re on WinForms then

Form2 form = new Form2();
form.show();



You can attach above code as soon as data insertion completes by save button.


You must use the Property or the public variable to cummunicate with the Form2 . While you changed you input or click the save button ,then you should cause the Form2''s event to change the DataGridView''s datasource and reband.


这篇关于将值从窗体传递到另一个Windows窗体的datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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