hi how can fetch the form2 dgv value into form1 textbox???? please reply
Satya nayak please help me how can fetch the form2 dgv value into form1 textbox???? please reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jul 13, 2012, 5:34 AM
backiyalakshmi KPosted Jul 14, 2012, 4:38 AM
VulpesPosted Jul 13, 2012, 10:33 AM
1. Form2 is not open when you're running this code; or
2. Form2 is not the correct name for the form (check its Name property in Properties Box).
backiyalakshmi KPosted Jul 13, 2012, 8:15 AM
backiyalakshmi KPosted Jul 13, 2012, 7:24 AM
backiyalakshmi KPosted Jul 13, 2012, 5:25 AM
VulpesPosted Jul 12, 2012, 10:26 AM
----------------------------------------------------------------------------------------
Suppose that:
1. The DGV on Form2 has been placed directly on that form and is called dataGridView1.
2. memcode and memname are displayed in row 0, columns 0 and 1 of dataGridView1.
Then the code to do that from Form1 would be:
private void textBox1_Click(object sender, System.EventArgs e)
{
Form2 f2 = (Form2)Application.OpenForms["Form2"];
DataGridView dgv = (DataGridView)f2.Controls["dataGridView1"];
textBox1.Text = dgv.Rows[0].Cells[0].Value.ToString();
textBox2.Text = dgv.Rows[0].Cells[1].Value.ToString();
}
----------------------------------------------------------------------------------------
A slightly easier way of doing things is to change the Modifiers property of dataGridView1 (in the Properties Box) from private to internal. It will then be visible to all other forms in the application without needing to go through the Controls collection.
If you do that first, the revised code will be: