Skip to main content
All docs
V24.2

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

DxTreeList.AllowDragRows Property

Specifies whether users can start the row drag operation.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
[DefaultValue(false)]
[Parameter]
public bool AllowDragRows { get; set; }

#Property Value

Type Default Description
Boolean false

true to allow users to start dragging rows; otherwise, false.

#Remarks

When you activate the AllowDragRows option, the TreeList component renders a drag handle for each data row:

Row Drag Handle

The AllowedDropTarget property value specifies whether users can reorder rows or move them to other components. To update the data source, handle the target component’s ItemsDropped event.

The following example implements row reordering within a TreeList:

Run Demo: Drag and Drop Rows - Reorder

Razor
<DxTreeList @ref="TreeList"
            Data="DataSource"
            KeyFieldName="Id"
            ParentKeyFieldName="ParentId"
            AllowDragRows="true"
            CssClass="max-h-480"
            ItemsDropped="TreeList_ItemsDropped">
    <Columns>
        <DxTreeListDataColumn FieldName="Name" Caption="Task" SortOrder="TreeListColumnSortOrder.Ascending" />
        <DxTreeListDataColumn FieldName="EmployeeName" Caption="Assigned To" TextAlignment="TreeListTextAlignment.Left" Width="200px" />
        <DxTreeListDataColumn FieldName="StartDate" Width="100px" />
        <DxTreeListDataColumn FieldName="DueDate" Width="100px" />
    </Columns>
</DxTreeList>

@code {
    ITreeList TreeList { get; set; }
    ObservableCollection<EmployeeTask> DataSource { get; set; }
    protected override void OnInitialized() {
        DataSource = new ObservableCollection<EmployeeTask>(EmployeeTaskDataProvider.GenerateData());
    }
    void TreeList_ItemsDropped(TreeListItemsDroppedEventArgs evt) {
        if(evt.TargetItem == null)
            return;
        var droppedTask = (EmployeeTask)evt.DroppedItems[0];
        DataSource.Remove(droppedTask);
        var targetTask = (EmployeeTask)evt.TargetItem;
        droppedTask.ParentId = evt.DropPosition == TreeListItemDropPosition.Inside
            ? targetTask.Id
            : targetTask.ParentId;
        var index = DataSource.IndexOf(targetTask) + (evt.DropPosition == TreeListItemDropPosition.After ? 1 : 0);
        DataSource.Insert(index, droppedTask);
    }
}
See Also