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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jul 13, 2012, 1:34 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 12, 2012, 6:26 AM EDT
----------------------------------------------------------------------------------------
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:
backiyalakshmi K38 reputationPosted Jul 13, 2012, 1:25 AM EDT
backiyalakshmi K38 reputationPosted Jul 13, 2012, 3:24 AM EDT
backiyalakshmi K38 reputationPosted Jul 13, 2012, 4:15 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 13, 2012, 6:33 AM EDT
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 K38 reputationPosted Jul 14, 2012, 12:38 AM EDT