繁体   English   中英

在父表单的文本框中显示值,在子表单中选择网格视图的单元格

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM