在 parent 形式的文本框中显示在 child 形式的 gridview 中选择的单元格的值
Show the value in textbox in the parent form, of a cell selected of the gridview in the child form
这是我的代码:
在 Parent 表格中:
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);
//}
此代码声明为public静态字符串代码,而code1只是字符串。
我还通过断点进行了检查,并且该值达到了 Parent 表单函数设置值中的函数,但我仍然无法在文本框中显示它。
伙计们谁能帮帮我....?
首先,将父表单传递给您的 Show()
调用。
变化:
help.Show();
收件人:
help.Show(this);
然后,在子表单中,您可以将 .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);
}
}
这是我的代码: 在 Parent 表格中:
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);
//}
此代码声明为public静态字符串代码,而code1只是字符串。 我还通过断点进行了检查,并且该值达到了 Parent 表单函数设置值中的函数,但我仍然无法在文本框中显示它。 伙计们谁能帮帮我....?
首先,将父表单传递给您的 Show()
调用。
变化:
help.Show();
收件人:
help.Show(this);
然后,在子表单中,您可以将 .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);
}
}