LayoutControl.ItemDragging Event

Fires repeatedly when a layout item is being dragged and allows you to prevent the item from being dropped at a specific position.

Namespace: DevExpress.XtraLayout

Assembly: DevExpress.XtraLayout.v20.1.dll

Declaration

[DXCategory("Action")]
public event EventHandler<ItemDraggingEventArgs> ItemDragging
<DXCategory("Action")>
Public Event ItemDragging As EventHandler(Of ItemDraggingEventArgs)

Event Data

The ItemDragging event's data class is DevExpress.XtraLayout.ItemDraggingEventArgs.

Remarks

Handle the ItemDragging event to perform actions while a layout item is being dragged, or to prevent the item from being dropped to specific positions.

The DragController event parameter provides the item movement settings. The DragItem property of this parameter returns the item currently being dragged, the Item property gets the item next to which the DragItem is about to be inserted. See the LayoutItemDragController class description to learn more about other features.

Use the AllowDrop event parameter to specify whether the item can be dropped at the current position.

Examples

This example handles the LayoutControl.ItemDragging event to prevent layout items from being moved between groups (in customization mode). The DragItem property of the DragController event parameter specifies the item being dragged. The Item property returns the item next to which the DragItem is about to be inserted. If the DragItem's parent doesn't match the Item's parent, the item is not allowed to be dropped at the target position. The AllowDrop event parameter is set to false in this case.

The following animation shows the result.

LayoutControl_ItemDraggingEventResult

private void layoutControl_ItemDragging(object sender, DevExpress.XtraLayout.ItemDraggingEventArgs e) {         
    if (e.DragController == null) return;
    if (e.DragController.DragItem == null || e.DragController.Item == null) return;
    if (e.DragController != null && e.DragController.Item != null && e.DragController.DragItem.Parent != e.DragController.Item.Parent) {
        e.AllowDrop = false;
    }
}
See Also