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.v24.1.dll
NuGet Package: DevExpress.Win.Navigation
Declaration
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.
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;
}
}