简体   繁体   English

将datagrid行值传递给下一个表单标签

[英]passing the datagrid row value to the next form label

hi i am working on winform and i have a datadrid view, i have a context menu strip. 嗨,我正在使用winform,我有一个datadrid视图,我有一个上下文菜单条。 on that edit is written. 在编辑上写。 when i click on datadrid, right click a context menu is open with edit. 当我点击datadrid时,右键单击上下文菜单打开并进行编辑。 when clicked it should pass the value to a new form, i have written the code for transfer but it is not passing i dont know whats the problem here 当点击它应该将值传递给一个新的表单,我已经写了转移的代码,但它没有通过我不知道这里的问题是什么

       private void editToolStripMenuItem_Click(object sender, EventArgs e)
    {
        Form6 f = new Form6();
     f.label1.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();

    }

is the code correct? 代码是否正确?

If Form6 is not already opened then you will need to show it after assigning text to its label. 如果Form6尚未打开,则需要在为其标签指定文本后显示它。

private void editToolStripMenuItem_Click(object sender, EventArgs e)
{
    Form6 f = new Form6();
    f.label1.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
    f.Show();

}

If Form6 is already opened, you need to use the instance of Form6 and not to create new instance, you can use Application.OpenForms to get already opened forms. 如果Form6已经打开,您需要使用Form6的实例而不是创建新实例,您可以使用Application.OpenForms来获取已经打开的表单。

Form6 f = (Form6)Application.OpenForms["form6"];
f.label1.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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