Skip to main content
A newer version of this page is available. .

TreeList.BeforeDragNode Event

Fires when an attempt to drag a node is performed.

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v19.2.dll

Declaration

public event BeforeDragNodeEventHandler BeforeDragNode

Event Data

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

Property Description
CanDrag Gets or sets a value indicating whether a Tree List node can be dragged.
Node Gets the current Tree List node. Inherited from NodeEventArgs.
Nodes Gets the list of nodes that are about to be dragged.
PreviewImage Gets 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.

using DevExpress.XtraTreeList;

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

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the BeforeDragNode event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also