Back to Devexpress

DragDropEvents.DragEnter Event

windowsforms-devexpress-dot-utils-dot-dragdrop-dot-dragdropevents-b2132e06.md

latest5.8 KB
Original Source

DragDropEvents.DragEnter Event

Occurs when a data element is dragged into the control’s bounds.

Namespace : DevExpress.Utils.DragDrop

Assembly : DevExpress.Utils.v25.2.dll

NuGet Packages : DevExpress.Utils, DevExpress.Wpf.Core

Declaration

csharp
[DXCategory("DragDrop")]
public event DragEnterEventHandler DragEnter
vb
<DXCategory("DragDrop")>
Public Event DragEnter As DragEnterEventHandler

Event Data

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

PropertyDescription
ActionGets or sets the drag-and-drop action (Copy, Move, etc.) to perform. Inherited from DXDragEventArgs.
AllowDropGets or sets whether it is allowed to drop data elements to the target control.
CursorGets or sets the mouse pointer. Inherited from DXDragEventArgs.
DataGets or sets the data elements being dragged. Inherited from DXDragEventArgs.
HandledGets or sets whether the event was handled and allows you to suppress the default action. Inherited from DXDefaultEventArgs.
KeyStateGets the pressed mouse buttons (left, middle, right) and modifier keys (Shift, Ctrl, Alt). Inherited from DXDragEventArgs.
LocationGets the mouse cursor’s position. Inherited from DXDragEventArgs.
SourceGets the source control. Inherited from DXDragEventArgs.
TargetGets the target control. Inherited from DXDragEventArgs.

The event data class exposes the following methods:

MethodDescription
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

This example shows how to prohibit to drop specific data.

csharp
private void dragDropEvents1_DragEnter(object sender, DragEnterEventArgs e) {
    List<TreeListNode> list = e.Data as List<TreeListNode>;
    // You can prohibit to drop specific data.
    if (list.Find((x) => x.GetValue(colDEPARTMENT1).ToString().Contains("Finance")) != null) {
        e.AllowDrop = false;
        e.Cursor = Cursors.No;
        e.Handled = true;
    }
}

private void dragDropEvents1_DragOver(object sender, DevExpress.Utils.DragDrop.DragOverEventArgs e) {
    List<TreeListNode> list = e.Data as List<TreeListNode>;
    // You can prohibit to drop specific data.
    if (list.Find((x) => x.GetValue(colDEPARTMENT1).ToString().Contains("Finance")) != null) {
        e.Cursor = Cursors.No;
        e.Handled = true;
    }
}
vb
Private Sub dragDropEvents1_DragEnter(ByVal sender As Object, ByVal e As DevExpress.Utils.DragDrop.DragEnterEventArgs) _
    Handles dragDropEvents1.DragEnter
    Dim list As List(Of TreeListNode) = TryCast(e.Data, List(Of TreeListNode))
    ' You can prohibit to drop specific data.
    If list.Find(Function(x) x.GetValue(colDEPARTMENT1).ToString().Contains("Finance")) IsNot Nothing Then
        e.AllowDrop = false
        e.Cursor = Cursors.No
        e.Handled = True
    End If
End Sub

Private Sub dragDropEvents1_DragOver(ByVal sender As Object, ByVal e As DevExpress.Utils.DragDrop.DragOverEventArgs) _
    Handles dragDropEvents1.DragOver
    Dim list As List(Of TreeListNode) = TryCast(e.Data, List(Of TreeListNode))
    ' You can prohibit to drop specific data.
    If list.Find(Function(x) x.GetValue(colDEPARTMENT1).ToString().Contains("Finance")) IsNot Nothing Then
        e.Cursor = Cursors.No
        e.Handled = True
    End If
End Sub

Note

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

See Also

DragDropEvents Class

DragDropEvents Members

DevExpress.Utils.DragDrop Namespace