c# devexpress data transfer between two grids with double click

296 Views Asked by At

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?

enter image description here

1

There are 1 best solutions below

6
muludag On

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);
        }
    }
}