Skip to main content

TreeList.CalcNodeDragImageIndex Event

Enables you to specify a custom image to be displayed in front of nodes during node drag-and-drop.

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v24.2.dll

Declaration

[DXCategory("DragDrop")]
public event CalcNodeDragImageIndexEventHandler CalcNodeDragImageIndex

Event Data

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

Property Description
DragArgs Gets an object which provides information for drag-and-drop events.
ImageIndex Gets or sets the index of the image to be displayed in front of nodes when dragging.
Node Gets the current Tree List node. Inherited from NodeEventArgs.
PtClient Gets the current mouse pointer’s coordinates relative to the top-left corner of the control.

Remarks

The Tree List control enables end users to perform drag-and-drop operations on nodes if this feature is enabled with the TreeListOptionsDragAndDrop.DragNodesMode setting.

When a user drops a node, it is inserted before, after, or as a child of the hovered node. This behavior depends on the SHIFT key status and the mouse cursor position within the node region.

DragDrop - Image

Handle the CalcNodeDragImageIndex event to display custom images in front of nodes during drag-and-drop operations. Assign the desired image index to the event’s CalcNodeDragImageIndexEventArgs.ImageIndex parameter. This index specifies the image’s position in the TreeList.Painter.NodeDragSvgImages image list. Add custom images to this list beforehand (for instance, on the form load) when required.

Note

The Tree List control does not guarantee that CalcNodeDragImageIndex and other Drag events are always raised in the same predefined order. Do not rely on the e.DragArgs.Effect parameter in the CalcNodeDragImageIndex event handler when you handle other Drag events to change the e.Effect parameter.

In such usage scenarios, check the same condition in Drag and CalcNodeDragImageIndex event handlers. Use Drag event handlers to set the required drag effect and the CalcNodeDragImageIndex event handler to specify the required drag image index based on your condition.

Example

The following sample code handles the TreeList.CalcNodeDragImageIndex event to display a custom image in front of parent nodes during drag-and-drop operations. The code adds the image to the painter’s image list to make the image available in the event handler.

DragDrop - CustomImage

using DevExpress.XtraTreeList;

// Add a custom image to the painter's image list
treeList1.Painter.NodeDragSvgImages.Add(SvgImage.FromFile("d:\\arrow.svg"));
// ...

private void treeList1_CalcNodeDragImageIndex(object sender, CalcNodeDragImageIndexEventArgs e) {
   // Display the custom image if the target node has children
   if (e.Node.HasChildren)
      e.ImageIndex = 3;
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CalcNodeDragImageIndex 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