[英]How can I retrive other values of form 1 when returning data from form2?
Code of form1
, 代码
form1
,
Picklist f2 = new Picklist(Query, this.Text);
f2.Show();
Code of form2
, form2
,
DataGridViewRow Row = dgvPicklist.Rows[index];
this.Hide();
ItemMaster f2 = new ItemMaster(Row);
f2.Show();
Okay, to send values from form1 to form2: 好的,要将值从form1发送到form2:
In form1: 在form1中:
form2 F = new form2(something); // something is the value you need to send
F.show();
In form2: 在form2中:
public form2(string x) //Considering the type of your value is string, you can replace that with the required data type.
{
string something = x; //sets the value of x to something. Just like it was in form1.
InitializeComponent();
}
I have considered the datatype of the value you wanted to transfer as string
. 我已经考虑过要作为
string
传输的值的数据类型。
You could change it as required. 您可以根据需要进行更改。
Use ShowModal()
Instead of Show()
: 使用
ShowModal()
代替Show()
:
Picklist f2 = new Picklist(Query, this.Text);
f2.ShowModal();
string valueFromForm1 = TextBox1.Text;
ShowModal()
waits till the opened form closes, and then executes the rest of the code ShowModal()
等待打开的窗体关闭,然后执行其余代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.