DragDropEvents.DragOver Event
Occurs when a data element is dragged over the control’s bounds.
Namespace: DevExpress.Utils.DragDrop
Assembly: DevExpress.Utils.v24.2.dll
NuGet Packages: DevExpress.Utils, DevExpress.Wpf.Core
#Declaration
#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 DXDrag |
Cursor |
Gets or sets the mouse pointer.
Inherited from DXDrag |
Data |
Gets or sets the data elements being dragged.
Inherited from DXDrag |
Handled |
Gets or sets whether the event was handled and allows you to suppress the default action.
Inherited from DXDefault |
Insert |
Gets or sets an image that represents the insert indicator. |
Insert |
Gets or sets the location of the default insert indicator. |
Insert |
Gets or sets the size of the default insert indicator. |
Insert |
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 Drag |
Key |
Gets the pressed mouse buttons (left, middle, right) and modifier keys (Shift, Ctrl, Alt).
Inherited from DXDrag |
Location |
Gets the mouse cursor’s position.
Inherited from DXDrag |
Source |
Gets the source control.
Inherited from DXDrag |
Tag |
Gets or sets custom data associated with the drag-and-drop operation.
Inherited from Drag |
Target |
Gets the target control.
Inherited from DXDrag |
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 DXDefault |
Get |
Returns the data elements being dragged.
Inherited from DXDrag |
#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 Drag
event for a grid view, use the static (Shared in VB) Drag
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 Xtra
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.Default();
e.Action = DragDropActions.None;
}
}