问题描述
我有一个datagridview表单,其名称为"Form1".datagridview的列名称为"id".
现在,我想将列名"id"传输(检索)到窗口应用程序中的"Form2"中.
那该怎么办,因为我们无法在窗口应用程序中使用会话".
因此,给出答案.
I have a datagridview a form which have name "Form1".The datagridview have the column name "id".
Now I want to transfer(retrieve) the column name "id" into the "Form2" in window apps.
So what can I do because we cannot use the "Session" in window apps.
So give the answer.
推荐答案
//FormTwo
public string szUserId;
onForm_Load()
{
Label.Text = szUserId;
}
现在在单击FormOne时显示FormTwo
通过创建FormTwo的对象,我们可以访问全局veriable并为其分配值
now show FormTwo on click on FormOne
By creating object of FormTwo, we can Access global veriable and assign values to it
FormOne_Button1_Click()
{
//create a object of formTwo
FormTwo frmtwo = new FormTwo();
//Access global veriable and assign values to it
frmtwo.szUserId = txtUserId.Text;
//Hide formOne
this.Hide();
//show formtwo
frmTwo.Show();
}
2.在formTwo上的构造函数中清除值
2. Declear value in constructor on formTwo
//FormTwopublic
string szUserId;
//in formtwo Constructor assign a value to it's veriable
FormTwo (string Uid)
{
Init()
this.szUserId = Uid
}
onForm_Load()
{
Label.Text = szUserId;
}
在FormOne上创建FormTwo的对象时传递userid值
on FormOne while creating Object of FormTwo pass the userid value
//FormOne FormTwo
frmtwo = new FormTwo(txtUserId.Text);
frmTwo.Show()
这篇关于如何在Window应用程序中的C#中将数据从一种形式传输到另一种形式.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!