![](/img/trans.png)
[英]Unable to get data from child form into selected Parent DataGridView Cell
[英]Show the value in textbox in the parent form, of a cell selected of the gridview in the child 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);
//}
此代碼聲明為公共靜態字符串代碼,而 code1 只是字符串。 我還檢查了斷點,該值到達了父表單函數設置值中的函數,但仍然無法在文本框中顯示它。 伙計們任何人都可以幫助我.....??
首先,將父表單傳遞給您的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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.