[英]Show the value in textbox in the parent form, of a cell selected of the gridview in the child form
This is my code: IN Parent form:这是我的代码:IN 父表单:
public void tokenform_Load(object sender, EventArgs e)
{
tbvarchecker.Text = HelpForm.code;
}
private void TextBox1_KeyDown(object sender, KeyEventArgs e)
{
HelpForm help = new HelpForm();
if (e.KeyCode == Keys.F2)
{
help.Show();
}
}
public void setvalues(string cd)
{
tbvarchecker.Text = cd;
label10.Text = cd;
}
Child Form code:
private void dgv(object sender, DataGridViewCellMouseEventArgs e)
{
DataGridViewRow row = dgvshowallfields.Rows[e.RowIndex];
code = row.Cells[0].Value.ToString();
code1 = row.Cells[0].Value.ToString();
this.Close();
}
private void HelpForm_FormClosed(object sender, FormClosedEventArgs e)
{
tokenform tkf = new tokenform();
tkf.setvalues(code);
tkf.setvalues(code1);
tkf.tokenform_Load(sender,e);
}
//private void HelpForm_FormClosing(object sender, FormClosingEventArgs e)
//{
// tkf.setvalues(code);
//}
This code is declared as public static string code, while the code1 is just string.此代码声明为公共静态字符串代码,而 code1 只是字符串。 I have also checked through breakpoints and the value reaches the function in Parent form function set values but still, I couldn't show it in the textbox.
我还检查了断点,该值到达了父表单函数设置值中的函数,但仍然无法在文本框中显示它。 Guys can anyone help me out.....??
伙计们任何人都可以帮助我.....??
First, pass the parent form to your Show()
call.首先,将父表单传递给您的
Show()
调用。
Change:改变:
help.Show();
To:到:
help.Show(this);
Then, in the child form, you can cast the .Owner
property to your parent form type and call its methods:然后,在子窗体中,您可以将
.Owner
属性转换为父窗体类型并调用其方法:
private void HelpForm_FormClosed(object sender, FormClosedEventArgs e)
{
tokenform tkf = this.Owner as tokenform;
if (tkf != null)
{
tkf.setvalues(code);
tkf.setvalues(code1);
tkf.tokenform_Load(sender,e);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.