Back to Devexpress

TreeList.BeforeDragNode Event

windowsforms-devexpress-dot-xtratreelist-dot-treelist-d88d7c20.md

latest4.6 KB
Original Source

TreeList.BeforeDragNode Event

Fires when an attempt to drag a node is performed.

Namespace : DevExpress.XtraTreeList

Assembly : DevExpress.XtraTreeList.v25.2.dll

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

Declaration

csharp
public event BeforeDragNodeEventHandler BeforeDragNode
vb
Public Event BeforeDragNode As BeforeDragNodeEventHandler

Event Data

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

PropertyDescription
CanDragGets or sets a value indicating whether a Tree List node can be dragged.
NodeGets the current Tree List node. Inherited from NodeEventArgs.
NodesGets the list of nodes that are about to be dragged.
PreviewImageGets or sets the image displayed near the mouse cursor during a drag-and-drop operation.

Remarks

Node drag-and-drop can be enabled with the TreeListOptionsDragAndDrop.DragNodesMode setting. The result of drag and drop operations performed over nodes is specified by the TreeListOptionsBehavior.AutoChangeParent and TreeListOptionsDragAndDrop.CanCloneNodesOnDrop options.

Each time an attempt to drag a node is made, the BeforeDragNode event fires. You can use this event to specify whether the node can be dragged. The BeforeDragNodeEventArgs.CanDrag event’s parameter must be set to false to prohibit node dragging. The node which is about to be dragged can be identified via the NodeEventArgs.Node parameter.

You may also want to perform specific actions each time a drag and drop operation has been canceled or successfully finished. This can be performed using the TreeList.AfterDragNode and TreeList.DragCancelNode events respectively.

Example

The following sample code prohibits parent node dragging. The TreeList.BeforeDragNode event is handled for this purpose. The TreeListNode.HasChildren property is used to identify whether the currently processed node has child nodes.

csharp
using DevExpress.XtraTreeList;

private void treeList1_BeforeDragNode(object sender, BeforeDragNodeEventArgs e) {
   if (e.Node.HasChildren) e.CanDrag = false;
}
vb
Imports DevExpress.XtraTreeList

Private Sub TreeList1_BeforeDragNode(ByVal sender As Object, _
ByVal e As BeforeDragNodeEventArgs) Handles TreeList1.BeforeDragNode
   If e.Node.HasChildren Then e.CanDrag = False
End Sub

See Also

CanDrag

AfterDragNode

DragCancelNode

BeforeDropNode

AfterDropNode

DoDragDropNode(TreeListNode, DragDropEffects)

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace