在Windows窗体应用程序中的窗口之间传递变量

编程入门 行业动态 更新时间:2024-10-23 11:20:52
本文介绍了在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窗体应用程序中的窗口之间传递变量

本文发布于:2023-11-11 10:37:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1578187.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗体   变量   应用程序   窗口   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!