To simply drag a grid row and drop it in another grindcontrol follow these steps below
forexample we have 2 gridcontrols with both a tableview, lets call them
grid1 and gridview1
grid2 and gridview2
first add these 2 events to yr gridview1:
MouseDown=”gridview1_MouseDown”
MouseMove=”gridview1_MouseMove”
Then add these 2 events and 1 property to yr gridview2:
DragEnter=”gridview2_DragEnter”
Drop=”gridview2_Drop”
AllowDrop=”True”
Then in code behind add this:
using DevExpress.Data;
bool _dragStarted = false;
// this is code for the gridview1
private void gridview1_MouseDown(object sender, MouseButtonEventArgs e)
{
int rowHandle = gridViewMedia.GetRowHandleByMouseEventArgs(e);
if (rowHandle != GridDataController.InvalidRow)
_dragStarted = true;
}
private void gridview1_MouseMove(object sender, MouseEventArgs e)
{
int rowHandle = gridview1.GetRowHandleByMouseEventArgs(e);
if (_dragStarted)
{
DataObject data = CreateDataObject(rowHandle);
FrameworkElement element = gridview1.GetRowElementByMouseEventArgs(e);
if(element != null)
DragDrop.DoDragDrop(element, data, DragDropEffects.Move | DragDropEffects.Copy);
_dragStarted = false;
}
}
private DataObject CreateDataObject(int rowHandle)
{
DataObject data = new DataObject();
data.SetData(typeof(int), rowHandle);
return data;
}
// ------------------------
// this is code for the gridview2
private void gridview2_DragEnter(object sender, DragEventArgs e)
{
e.Effects = DragDropEffects.Copy;
e.Handled = true;
}
private void gridview2_Drop(object sender, DragEventArgs e)
{
int rowHandle = (int)e.Data.GetData(typeof(int));
MyObject myObject = (MyObject)grid1.GetRow(rowHandle);
if (myObject != null)
{
// this is just a list/ List<MyObjects>
_droppedItems.Add(myObject);
// clear the datasource, and reload it the datasource with the new object added to the collection
grid2.ItemsSource = null;
grid2.ItemsSource = _droppedItems;
// optional remove the focus from the grid
gridview2.FocusedRowHandle = -1;
// remove the row from the grid1
grid1.DeleteRow(rowHandle);
}
}
// ------------------------