Skip to main content

DragDropManager.DragDrop Event

Occurs when a data element is dropped on the control.

Namespace: DevExpress.Utils.DragDrop

Assembly: DevExpress.Utils.v24.2.dll

Declaration

[DXCategory("DragDrop")]
public event DragDropEventHandler DragDrop

Event Data

The DragDrop event's data class is DragDropEventArgs. The following properties provide information specific to this event:

Property Description
Action Gets or sets the drag-and-drop action (Copy, Move, etc.) to perform. Inherited from DXDragEventArgs.
Cursor Gets or sets the mouse pointer. Inherited from DXDragEventArgs.
Data Gets or sets the data elements being dragged. Inherited from DXDragEventArgs.
Handled Gets or sets whether the event was handled and allows you to suppress the default action. Inherited from DXDefaultEventArgs.
InsertType Gets or sets whether dragged data elements are inserted before or after a data element under the mouse pointer, or as a child (for tree list only). Inherited from DragOverEventArgsBase.
KeyState Gets the pressed mouse buttons (left, middle, right) and modifier keys (Shift, Ctrl, Alt). Inherited from DXDragEventArgs.
Location Gets the mouse cursor’s position. Inherited from DXDragEventArgs.
Source Gets the source control. Inherited from DXDragEventArgs.
Tag Gets or sets custom data associated with the drag-and-drop operation. Inherited from DragOverEventArgsBase.
Target Gets the target control. Inherited from DXDragEventArgs.

The event data class exposes the following methods:

Method Description
Default() Invokes the default action the attached control performs on the current drag-and-drop operation stage. Inherited from DXDefaultEventArgs.
GetData<T>() Returns the data elements being dragged. Inherited from DXDragEventArgs.

Example

The example below shows how to copy data from a tree list to a grid.

using DevExpress.Utils.DragDrop;

//The code below assumes that you are moving data from a tree list to a grid.
//Create new grid rows, and populate them with data from tree list nodes.
private void dragDropEvents1_DragDrop(object sender, DragDropEventArgs e) {
    List<TreeListNode> list = e.Data as List<TreeListNode>;
    foreach (TreeListNode node in list) {
        gridView1.AddNewRow();
        gridView1.SetRowCellValue(GridControl.NewItemRowHandle, gridView1.Columns["DEPARTMENT"], node.GetValue(colDEPARTMENT1));
    }
    e.Handled = true;
}

Note

When you handle the DragDrop event for a grid view, use the static (Shared in VB) DragDropGridEventArgs.GetDragDropGridEventArgs method to calculate arguments specific to the grid view.

using DevExpress.Utils.DragDrop;
using DevExpress.XtraGrid.Views.Grid;

dragDropEvents1.DragDrop += Behavior_DragDrop;

private void Behavior_DragDrop(object sender, DragDropEventArgs e) {
   DragDropGridEventArgs args = DragDropGridEventArgs.GetDragDropGridEventArgs(e);
   //You can also cast DragDropEventArgs to DragDropGridEventArgs.
   //DragDropGridEventArgs args = (DragDropGridEventArgs)e;
}

Note

Run the XtraTreeList or XtraGrid demo and click Open Solution for more examples.

See Also