dataGridView_DoubleClick
-
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
-
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
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
-
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
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
-
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
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
-
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
hey, thank you so much...it works! regards :-D :rose:
jing