Home > DeveloperSection > Forums > How to pass datagridview's cells value to another window form
Ankit Singh

Total Post:341

Points:2389
Posted on    January-05-2013 4:23 AM

 C# C# 
Ratings:


 3 Reply(s)
 5200  View(s)
Rate this:
Hi,

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

Thank in advance


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    January-05-2013 7:07 AM

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.

Demir ACAR
Demir ACAR

Total Post:11

Points:77
Posted on    February-10-2014 10:08 AM

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

Demir ACAR
Demir ACAR

Total Post:11

Points:77
Posted on    February-11-2014 9:02 AM

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

Don't want to miss updates? Please click the below button!

Follow MindStick