Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. dataGridView_DoubleClick

dataGridView_DoubleClick

Scheduled Pinned Locked Moved C#
database
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    balanjingot
    wrote on last edited by
    #1

    hi, i have this datagridview that will transfer (by double clicking) the selected celrow to another datagridview.but the selected row value will be displayed on the selected cell of the other datagridview. i hope i made myself clear:doh: private void dataGridView4_DoubleClick(object sender, EventArgs e) { int rowIndex = dataGridView4.CurrentRow.Index; //selected row of source datagridview int currentCell = dataGridView2.CurrentRow.Index;//selected cell of the destination datagridview long supplier1 = 0; long currentColumn = 0; supplier1 = Convert.ToInt64(dataGridView4.Rows[rowIndex].Cells[0].Value.ToString()); //value of selected row string[] data = { supplier1.ToString() }; if (currentCell == 5) //destination datagridview's cell index { dataGridView2.Rows.Add(data);//add value to destination } } its not working..:((will pls give me a sample snippet..tnx!! regards:rose:

    jing

    G 1 Reply Last reply
    0
    • B balanjingot

      hi, i have this datagridview that will transfer (by double clicking) the selected celrow to another datagridview.but the selected row value will be displayed on the selected cell of the other datagridview. i hope i made myself clear:doh: private void dataGridView4_DoubleClick(object sender, EventArgs e) { int rowIndex = dataGridView4.CurrentRow.Index; //selected row of source datagridview int currentCell = dataGridView2.CurrentRow.Index;//selected cell of the destination datagridview long supplier1 = 0; long currentColumn = 0; supplier1 = Convert.ToInt64(dataGridView4.Rows[rowIndex].Cells[0].Value.ToString()); //value of selected row string[] data = { supplier1.ToString() }; if (currentCell == 5) //destination datagridview's cell index { dataGridView2.Rows.Add(data);//add value to destination } } its not working..:((will pls give me a sample snippet..tnx!! regards:rose:

      jing

      G Offline
      G Offline
      Gopal S
      wrote on last edited by
      #2

      Hi balanjingot, You can use CellDoubleClick event instead of DatagridView DoubleClick. Here is the code snipet: private void Form1_Load(object sender, EventArgs e) { DataTable dtable = new DataTable(); dtable.Columns.Add("SNo"); dtable.Columns.Add("Name"); for (int i = 0; i < 5; i++) { DataRow dr = dtable.NewRow(); dr[0] = "1" + i.ToString(); ; dr[1] = "Name " + i.ToString(); dtable.Rows.Add(dr); } dataGridView1.DataSource = dtable; DataTable dtable2 = new DataTable(); dtable2.Columns.Add("SNo"); dtable2.Columns.Add("Name"); for (int i = 0; i < 5; i++) { DataRow dr = dtable2.NewRow(); dr[0] = "2" + i.ToString(); ; dr[1] = "Name " + i.ToString(); dtable2.Rows.Add(dr); } dataGridView2.DataSource = dtable2; } private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { dataGridView2.CurrentRow.Cells[0].Value = dataGridView1.CurrentRow.Cells[0].Value; dataGridView2.CurrentRow.Cells[1].Value = dataGridView1.CurrentRow.Cells[1].Value; } Please let me know if this helps. Thanks, S.Gopal.

      Gopal.S

      B 1 Reply Last reply
      0
      • G Gopal S

        Hi balanjingot, You can use CellDoubleClick event instead of DatagridView DoubleClick. Here is the code snipet: private void Form1_Load(object sender, EventArgs e) { DataTable dtable = new DataTable(); dtable.Columns.Add("SNo"); dtable.Columns.Add("Name"); for (int i = 0; i < 5; i++) { DataRow dr = dtable.NewRow(); dr[0] = "1" + i.ToString(); ; dr[1] = "Name " + i.ToString(); dtable.Rows.Add(dr); } dataGridView1.DataSource = dtable; DataTable dtable2 = new DataTable(); dtable2.Columns.Add("SNo"); dtable2.Columns.Add("Name"); for (int i = 0; i < 5; i++) { DataRow dr = dtable2.NewRow(); dr[0] = "2" + i.ToString(); ; dr[1] = "Name " + i.ToString(); dtable2.Rows.Add(dr); } dataGridView2.DataSource = dtable2; } private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { dataGridView2.CurrentRow.Cells[0].Value = dataGridView1.CurrentRow.Cells[0].Value; dataGridView2.CurrentRow.Cells[1].Value = dataGridView1.CurrentRow.Cells[1].Value; } Please let me know if this helps. Thanks, S.Gopal.

        Gopal.S

        B Offline
        B Offline
        balanjingot
        wrote on last edited by
        #3

        hi, thanks, it works. the value from datagridview1 will be transfered to datagridview 2. but what if i want it this way... dataGridView2.CurrentRow.Cells[5].Value = dataGridView1.CurrentRow.Cells[0].Value; dataGridView2.CurrentRow.Cells[6].Value = dataGridView1.CurrentRow.Cells[0].Value; if i select Cell 5 of dgv2, the selected value of cell 0 of dgv1 will displayed on cell 5 of dgv2 if i select cell 6 of dgv2, the selected value of cell 0 of dgv1 will be displayed on cell 6 of dgv2? thanks..hoping for a reply:rose:

        jing

        G 1 Reply Last reply
        0
        • B balanjingot

          hi, thanks, it works. the value from datagridview1 will be transfered to datagridview 2. but what if i want it this way... dataGridView2.CurrentRow.Cells[5].Value = dataGridView1.CurrentRow.Cells[0].Value; dataGridView2.CurrentRow.Cells[6].Value = dataGridView1.CurrentRow.Cells[0].Value; if i select Cell 5 of dgv2, the selected value of cell 0 of dgv1 will displayed on cell 5 of dgv2 if i select cell 6 of dgv2, the selected value of cell 0 of dgv1 will be displayed on cell 6 of dgv2? thanks..hoping for a reply:rose:

          jing

          G Offline
          G Offline
          Gopal S
          wrote on last edited by
          #4

          Hi, Please use this code: dataGridView2.CurrentCell.Value = dataGridView1.CurrentCell.Value; instead of, dataGridView2.CurrentRow.Cells[5].Value = dataGridView1.CurrentRow.Cells[0].Value; dataGridView2.CurrentRow.Cells[6].Value = dataGridView1.CurrentRow.Cells[0].Value; Thanks,

          Gopal.S

          B 1 Reply Last reply
          0
          • G Gopal S

            Hi, Please use this code: dataGridView2.CurrentCell.Value = dataGridView1.CurrentCell.Value; instead of, dataGridView2.CurrentRow.Cells[5].Value = dataGridView1.CurrentRow.Cells[0].Value; dataGridView2.CurrentRow.Cells[6].Value = dataGridView1.CurrentRow.Cells[0].Value; Thanks,

            Gopal.S

            B Offline
            B Offline
            balanjingot
            wrote on last edited by
            #5

            hey, thank you so much...it works! regards :-D :rose:

            jing

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups