Back to Devexpress

LayoutControl.ItemDragging Event

windowsforms-devexpress-dot-xtralayout-dot-layoutcontrol-05809603.md

latest3.5 KB
Original Source

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.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Action")]
public event EventHandler<ItemDraggingEventArgs> ItemDragging
vb
<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.

Example

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.

csharp
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;
    }
}
vb
Private Sub layoutControl_ItemDragging(sender As Object, e As DevExpress.XtraLayout.ItemDraggingEventArgs)
    If e.DragController Is Nothing Then
        Return
    End If
    If e.DragController.DragItem Is Nothing OrElse e.DragController.Item Is Nothing Then
        Return
    End If
    If e.DragController IsNot Nothing AndAlso e.DragController.Item IsNot Nothing AndAlso e.DragController.DragItem.Parent <> e.DragController.Item.Parent Then
        e.AllowDrop = False
    End If
End Sub

See Also

LayoutControl Class

LayoutControl Members

DevExpress.XtraLayout Namespace