Skip to main content

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.v24.1.dll

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

Declaration

[DXCategory("DragDrop")]
public event BeforeDropNodeEventHandler BeforeDropNode

Event Data

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

Property Description
Cancel Gets or sets a value that specifies whether to cancel the action.
DestinationIndex Gets the position of the node among the child nodes of the parent node after drop.
DestinationNode Gets a parent node that owns the dropped node.
IsCopy Gets whether the user copied or moved a node.
SourceNode Gets 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.

private void treeList1_BeforeDropNode(object sender, DevExpress.XtraTreeList.BeforeDropNodeEventArgs e){
    if (e.DestinationNode.HasChildren == false) e.Cancel = true;
}

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

See Also