I have 2 gridviews. I list my products in the first grid and I want to transfer the product to be selected by the user from this list by double-clicking on the next grid. (with double click) How can I do it?
Asked
Active
Viewed 240 times
1 Answers
0
I used below codes to transfer the double clicked row to another grid control and it works. Same or similar codes may be work for you.
private void gridView1_DoubleClick(object sender, EventArgs e)
{
GridView view = sender as GridView;
DevExpress.Utils.DXMouseEventArgs ea = e as DevExpress.Utils.DXMouseEventArgs;
DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo info = view.CalcHitInfo(ea.Location);
if (view == gridView1)//ilk girdden mi double click yapılmış...
{
if (info.InRow)//row'a mı double click yapılmış
{
DataTable dtsource = gridView1.GridControl.DataSource as DataTable;
DataTable dtdestination = gridControl2.DataSource as DataTable;//eklenecek grid
DataRow sourcerow = (DataRow)((DataRowView)view.GetRow(info.RowHandle)).Row;
DataRow dr = dtdestination.NewRow();
dr.ItemArray = sourcerow.ItemArray;
dtdestination.Rows.InsertAt(dr, gridView2.DataRowCount);
dtsource.Rows.Remove(sourcerow);
}
}
}

muludag
- 134
- 1
- 8
-
Which line of code did it fail? I used data tables to data grid data source. it can be the difference between my code and yours. – muludag Nov 15 '21 at 05:15
-
Hi, I still have a problem with the subject :( I get the data to the first gridcontrol as follows and when I double click on any row, I want that row to be transferred to the gridcontrol. – Sinem Hür Dec 07 '21 at 12:54
-
DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter("Select * from blabla", bgl.baglanti()); da.Fill(dt); gridControl1.DataSource = dt; – Sinem Hür Dec 07 '21 at 12:55
-
Two data sources of grid controls are different so a row from first grid won't be transferred directly to second grid. Are you trying to just copy or clone row data to another in other words deleting the row from first grid and adding a row that has the row data to second grid, right? – muludag Dec 07 '21 at 13:25
-
Yes, I am trying to add the double clicked row to the 2nd gridcontrol. It will not be deleted from other gridcontrol, it will just be added to gridcontrol2 when clicked. (clone) – Sinem Hür Dec 07 '21 at 14:06
-
You can change the code line that has item values according to column names like "dr.ItemArray = new List – muludag Dec 07 '21 at 14:38