This is an example for the Drag-and-drop data rows from one grid to another Knowledge Base article. Please refer to the article for the explanation.
Question Comments
Added By: Carlos Arias at: 10/9/2012 1:52:58 PM
GridControl grid = sender as GridControl;
grid always null ???
Thanx Dear fro reply me i'll do it
Added By: david ola at: 11/5/2015 5:41:44 AM1. Can you copy instead from the original grid rather than deleting the row being dragged? In other words, after dragging a particular row, let the original grid still have the row, as opposed to the row disappearing.
2. Can you modify the code such that the row being dragged can be captured and displayed, modified before it is dropped?
David,
Just change the DragDrop handler to not import and delete the source and instead create a copy of the DataRow and import that into the second grid.
Added By: Sasha (DevExpress Support) at: 11/5/2015 11:05:33 AMHello David,
Here is a small code that illustrates Brendon's idea:
[C#]privatevoidgrid_DragDrop(objectsender,System.Windows.Forms.DragEventArgse){GridControlgrid=senderasGridControl;DataTabletable=grid.DataSourceasDataTable;DataRowrow=e.Data.GetData(typeof(DataRow))asDataRow;if(row!=null&&table!=null&&row.Table!=table){table.ImportRow(row);table.Rows[table.Rows.Count-1]["Column1"]="modified";}}
Please review it and let me know if it helps.
Added By: david ola at: 11/6/2015 5:07:05 AMThanks guys, but I am still having a problem: the original data in the first grid is still being modified. Here is my code:
GridControl grid = sender as GridControl;
DataTable table = grid.DataSource as DataTable;
DataRow row = e.Data.GetData(typeof(DataRow)) as DataRow;
int newNum = 0;
num += 1;
if (row != null && table != null && row.Table != table)
{
DataRow rowmod = row;
rowmod[0] = "original modified";
MessageBox.Show(rowmod[0].ToString());
newNum = num % 2;
if (newNum == 0)
{
table.ImportRow(rowmod);
}
}
I want only the imported row to be modifiable without any changes to the original data.
My intention is to allow the user to drag the row, display that row in a form for possible modification, before dropping it in the second grid. The user should also be able to cancel the operation without making any changes to either grid, even after displaying the row in the form.
So far I have been able to display and modify the data, and even choosing to cancel mid-operation (using the modulo example). But it keeps making changes to the original data, which I don't want.
Hello David,
I've created a separate ticket for your inquiry: How to modify the 'Drag-and-drop data rows from one grid to another' example so that the row is not deleted after dragging. Let's continue discussing it in that thread.
It would be possible to do this with a CardView ?Added By: Alexey Z (DevExpress Support) at: 6/22/2016 12:49:22 AM
Hello,
I've created a separate ticket on your behalf (T394874: XtraGridControl - How to implement Drag&Drop mechanism between two CardViews). It has been placed in our processing queue and will be answered shortly.