Hi AmerShokry-5319,
Based on your description, I made a test.
Please refer to the following for specific steps:
1.First, add a new Form2 and set it to mdiform(set Form1's isMdiContainer property to true ).
Then open the mdiform(Form2) by clicking the New item in MenuStrip control.
Form1.cs
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.MdiParent = this;
f2.Show();
}
2.Add textbox and button controls into Form2.
3.Add a new form(Form3) and add DataGridView control to it. Fill data to DataGridView.
4.Open Form3 by clicking the button in Form2.
Form2.cs
private void button1_Click(object sender, EventArgs e)
{
Form3 f3 = new Form3();
f3.Show();
}
5.Pass DataGridView row valus into TextBox in Form2 via DataGridView.RowHeaderMouseDoubleClick event.
Note: you need to select the TextBox control and in Properties window set the Modifiers property to Public and then you can simply access this control using its name from outside of the Form.
Form3.cs
private void dataGridView1_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
Form2 fr= (Form2)Application.OpenForms["Form2"];
int row = e.RowIndex;
fr.textBox1.Text = Convert.ToString(dataGridView1[0, row].Value);
fr.textBox2.Text = Convert.ToString(dataGridView1[1, row].Value);
}
Here is my test result:
If you want to use ShowDialog(), please refer to this thread.
And here is a related thread.
Best Regards,
Daniel Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.