Back to Devexpress

TreeList.BeforeDropNode Event

windowsforms-devexpress-dot-xtratreelist-dot-treelist-13439eca.md

latest4.2 KB
Original Source

TreeList.BeforeDropNode Event

Fires when a node is about to be dropped, and allows you to cancel the operation.

Namespace : DevExpress.XtraTreeList

Assembly : DevExpress.XtraTreeList.v25.2.dll

NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.TreeList

Declaration

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

Event Data

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

PropertyDescription
CancelGets or sets a value that specifies whether to cancel the action.
DestinationIndexGets the position of the node among the child nodes of the parent node after drop.
DestinationNodeGets a parent node that owns the dropped node.
IsCopyGets whether the user copied or moved a node.
SourceNodeGets a node that the user is about to drop.

Remarks

TreeList control nodes can be moved using drag-and-drop operations if the TreeListOptionsDragAndDrop.DragNodesMode option (accessible through the TreeList.OptionsBehavior property) is set to Single or Multiple.

The BeforeDropNode event fires when a node is about to be dropped, and allows you to cancel the operation. The BeforeDropNodeEventArgs.SourceNode property allows you to determine the node being processed. To get the destination parent node, read the DestinationNode property.

Unlike the TreeList.BeforeDragNode event, which allows you to cancel a drag-and-drop operation when it starts, the BeforeDropNode event allows you to cancel the operation when the node being dragged is about to be dropped. The code snippet below shows how to prohibit dropping nodes onto parent nodes that correspond to a particular condition.

csharp
private void treeList1_BeforeDropNode(object sender, DevExpress.XtraTreeList.BeforeDropNodeEventArgs e){
    if (e.DestinationNode.HasChildren == false) e.Cancel = true;
}
vb
Private Sub treeList1_BeforeDropNode(sender As Object, e As DevExpress.XtraTreeList.BeforeDropNodeEventArgs)
    If e.DestinationNode.HasChildren = False Then
        e.Cancel = True
    End If
End Sub

After the BeforeDropNode event is fired, the TreeList.AfterDropNode event fires.

See Also

BeforeDragNode

AfterDragNode

AfterDropNode

DragCancelNode

DragNodesMode

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace