Skip to main content
All docs
V24.2

DxTreeList.SelectedDataItems Property

In multiple selection mode, this property specifies data items that correspond to selected TreeList rows.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

[Parameter]
public IReadOnlyList<object> SelectedDataItems { get; set; }

Property Value

Type Description
IReadOnlyList<Object>

The data item collection.

Remarks

The TreeList supports multiple row selection when the SelectionMode property is set to Multiple (the default value). To access data items that correspond to the selected rows, use the SelectedDataItems property as follows:

  • Implement two-way binding for this property (@bind-SelectedDataItems) to specify initially selected rows and automatically update the property value when selection changes.
  • Use one-way binding for this property and handle the SelectedDataItemsChanged event to implement a custom response to selection changes.

If SelectionMode is set to Single, use the SelectedDataItem property instead. If you change the selection mode dynamically, specify the SelectedDataItems property and handle the SelectedDataItemsChanged event. In the event handler, check the selection mode and assign the last selected item or all selected items to the SelectedDataItems property.

For more information about selection in the TreeList component, refer to the following topic: Selection and Focus in Blazor TreeList.

Select and Deselect Items

Rows can be selected and deselected in the following ways:

  • A user clicks rows, taps rows, or executes keyboard shortcuts to select or deselect rows. To enable this functionality, set the AllowSelectRowByClick property to true.
  • A user clicks checkboxes in the selection column. To display this column, declare a DxTreeListSelectionColumn object in the Columns template.
  • You call the Select* or Deselect* method. Refer to the TreeList’s member table for the list of available methods.

Obtain Item Field Values

Pass a data item to the GetDataItemValue method to get the item’s field value when the TreeList is bound to a collection of anonymous objects. In other cases, you can cast a data item to the corresponding type and use the {DataItem.FieldName} notation to get the item’s field value.

The following example allows users to click rows to select them and displays information about the selected rows:

@inject EmployeeTaskService EmployeeTaskService

<DxTreeList Data="TreeListData"
            KeyFieldName="Id"
            ParentKeyFieldName="ParentId"
            AllowSelectRowByClick="true"
            @bind-SelectedDataItems="@SelectedDataItems">
    <Columns>
        <DxTreeListDataColumn FieldName="Name" Caption="Task" />
        <DxTreeListDataColumn FieldName="EmployeeName" />
        <DxTreeListDataColumn FieldName="StartDate" />
        <DxTreeListDataColumn FieldName="DueDate" />
    </Columns>
</DxTreeList>

<div>
    <b>Selected tasks:</b>
    @{
        if(SelectedDataItems != null)
            foreach (var task in SelectedDataItems.Cast<EmployeeTask>()) {    
                <li>@task.Name</li>
            }
    }
</div>

@code {
    List<EmployeeTask> TreeListData { get; set; }
    IReadOnlyList<object> SelectedDataItems { get; set; }

    protected override void OnInitialized() {
        TreeListData = EmployeeTaskService.GenerateData();
    }
}

Blazor TreeList Obtain Selected Data Items

Run Demo: TreeList - Multiple Row Selection

You can use the SelectedDataItems property to delete selected rows when a user clicks a button.

See Also