DragDropEvents.DragOver Event

Occurs when a data element is dragged over the control's bounds.

Namespace: DevExpress.Utils.DragDrop

Assembly: DevExpress.Utils.v20.1.dll

Declaration

[DXCategory("DragDrop")]
public event DragOverEventHandler DragOver
<DXCategory("DragDrop")>
Public Event DragOver As DragOverEventHandler

Event Data

The DragOver event's data class is DragOverEventArgs. 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.
InsertIndicator Gets or sets an image that represents the insert indicator.
InsertIndicatorLocation Gets or sets the location of the defalt insert indicator.
InsertIndicatorSize Gets or sets the size of the default insert indicator.
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).
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.
Target Gets the target control. Inherited from DXDragEventArgs.

Examples

The example below shows how to cancel an operation if Ctrl is not pressed.

using DevExpress.Utils.DragDrop;

//The operation is only allowed when Ctrl is pressed.
private void dragDropEvents1_DragOver(object sender, DragOverEventArgs e) {
    e.Default();
    if (e.KeyState.HasFlag(DragDropKeyState.Control)) {
        e.Cursor = Cursors.Arrow;
        e.Action = DevExpress.Utils.DragDrop.DragDropActions.Copy;
    } else {
        e.Cursor = Cursors.No;
        e.Action = DragDropActions.None;
    }
}
NOTE

When you handle the DragOver event for a grid view, use the static (Shared in VB) DragOverGridEventArgs.GetDragOverGridEventArgs method to calculate arguments specific to the grid view.

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

dragDropEvents1.DragOver += Behavior_DragOver;

private void Behavior_DragOver(object sender, DragOverEventArgs e) {
   DragOverGridEventArgs args = DragOverGridEventArgs.GetDragOverGridEventArgs(e);
   //You can also cast DragOverEventArgs to DragOverGridEventArgs.
   //DragOverGridEventArgs args = (DragOverGridEventArgs)e;
}
NOTE

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

The code below shows how to prohibit the user to drag an item to the tree list's third level or lower. The example uses the CalcHitInfo(Point) method to get the tree list's visual element under the mouse pointer. To determine the hierarchy level at which a particular node resides, use the Level property.

using DevExpress.Utils.DragDrop;
using DevExpress.XtraTreeList;

private void dragDropEvents1_DragOver(object sender, DevExpress.Utils.DragDrop.DragOverEventArgs e) {
    TreeList treeList = e.Target as TreeList;
    var hitInfo = treeList.CalcHitInfo(treeList.PointToClient(e.Location));
    var treeListNode = hitInfo.Node;
    if (treeListNode.Level >= 3)
        e.Action = DragDropActions.None;
}
See Also