Drag and Drop Grid Control Row DevExpress WPF

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:

Then add these 2 events and 1 property to yr gridview2:

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>

	// 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

// ------------------------

About johnnblade aka johnnyblade Thugnology

C# Developer 9Ja Thugnology
This entry was posted in WPF & DevExpress and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s