How to pass datagridview's cells value to another window form

Total Post:341

Points:2389
C# 
C#
 7499  View(s)
Ratings:
Rate this:
Hi,

I want to pass DataGridView cells values to another windows form Textbox, how i can do this?

Thank in advance
  1. Post:604

    Points:4228
    Re: How to pass datagridview's cells value to another window form

    Hi Ankit Singh

                   //Create instance of the form2 class
                    form2 obj = new form2 ();
                    //Bind the datagridview values in the second popup form
                    obj.Controls["TextBox1"].Text = dgvControl.Rows[e.RowIndex].Cells[1].Value.ToString();
                    obj.Controls["TextBox2"].Text = dgvControl.Rows[e.RowIndex].Cells[2].Value.ToString();
                    obj.Controls["TextBox3"].Text = dgvControl.Rows[e.RowIndex].Cells[3].Value.ToString();
                    obj.ShowDialog();

    Here Rows[e.RowIndex].Cells[1],[2],[3] are the cell index which value pass to form2.

  1. Post:11

    Points:77
    Re: How to pass datagridview's cells value to another window form

    Hi PATEL ;

    I applied your's code but have some problem ,Everything is working except Form2 Don't close , if you see picture you can unserdtand What I will try to do .




                obj.Controls["TextBox1"].Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();           Form4 obj = new Form4();

              obj.Controls["TextBox2"].Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();

                obj.Controls["maskedTextBox1"].Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();

                obj.Controls["TextBox7"].Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();

                obj.Controls["TextBox6"].Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();

                obj.Controls["TextBox3"].Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();

                obj.Controls["TextBox4"].Text = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();

                obj.Controls["TextBox5"].Text = dataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString();

                obj.ShowDialog();

                Form3 frm = new Form3();

                obj.Hide();

                this.Hide();

                frm.Show();


      Modified On Feb-10-2014 02:05:56 PM
  1. Post:11

    Points:77
    Re: How to pass datagridview's cells value to another window form

    Problem was solved ,I can close the Form using Active.Form element

Answer