在Windows窗体应用程序中的窗口之间传递变量 [英] Passing variables between windows in Windows Forms Application

查看:114
本文介绍了在Windows窗体应用程序中的窗口之间传递变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个窗口,(Form1和EditRecord)。在Form1上有一个gridview,它由填充查询(SQL数据库)填充。我希望用户从表中选择一条记录,然后单击btnEdit记录将所选记录移动到新窗口。以下代码是我在EditRecord窗口中的代码。我的SQL查询中的键列是GUID。我编写了一个SQL查询来参数化GUID,我称之为FillByGUID。以下是我的EditRecord窗口中的代码:



I have two windows, (Form1 and EditRecord). On Form1 there is a gridview that is populated by a fill query (SQL Database). I want the user to select a record from the table and click btnEdit record to move the selected record to a new window. The following code is what I have in my EditRecord window. The key column in my SQL query is GUID. I have written a SQL query that parametizes the GUID and I've called that FillByGUID. Here is the code on my EditRecord window:

internal void LoadOrders(String GUID)
       {
           this.cj96TBRiscTableAdapter.FillByCustomerID(this.cj96DataSet.cj96TBRisc, GUID);
       }







有人可以帮帮我吗?如果您需要任何其他信息,请告诉我,我会发布。




Can someone please help me on this? If you need any other information let me know and I'll post it.

推荐答案

具体如何执行此操作取决于表单之间的关系:如果您创建一个一个在另一个的实例,然后第一个是父母,第二个是孩子:

在两种形式之间传递信息,第1部分:父母对儿童 [ ^ ]

在两种形式之间传递信息,第2部分:儿童到父母 [ ^ ]

在两种表格之间传递信息,第3部分:儿童与儿童 [ ^ ]
Exactly how you do this depends on the relationship between the forms: If you create an instance of one in another, then the first is the parent, the second is the child:
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]


将EditRecord表单的构造函数更改为接受一个字符串作为参数。



Change your EditRecord form's constructor to accept a string as a parameter.

private string GUID;

public EditRecord(string GUID)
{
     this.GUID = GUID;
}





然后当你在Form1中初始化EditRecord时,将值传递给构造函数。





Then when you initialise EditRecord in Form1 pass the value into the constructor.

EditRecord editRecord = new EditRecord(GUID);
editRecord.Visible = true


这篇关于在Windows窗体应用程序中的窗口之间传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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