Skip to main content
All docs
V24.1

DxTreeList.AllowSelectRowByClick Property

Specifies whether users can select and deselect rows by mouse clicks, tap gestures, and keyboard shortcuts.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.1.dll

NuGet Package: DevExpress.Blazor

Declaration

[DefaultValue(false)]
[Parameter]
public bool AllowSelectRowByClick { get; set; }

Property Value

Type Default Description
Boolean false

true to allow users to select and deselect rows by mouse clicks, tap gestures, and keyboard shortcuts; otherwise, false.

Remarks

Set the AllowSelectRowByClick property to true to enable the following user operations:

Operation Description
Click Click a row to select it and clear the selection of all other rows.
Ctrl+Click Hold down the Ctrl key and click a row to add/remove the row to/from selection.
Shift+Click Click the first row in a range, hold down the Shift key, and click the last row in the range to select a range of rows.
Ctrl+Shift+Click Hold down the Ctrl key, click the first row in the range, hold down the Shift key, and click the last row in the range to add the range of rows to the selection.
Space Focus a cell in a row and press Space to select the row and clear the selection of all other rows.
Tap Tap a row to select it and clear the selection of all other rows.
Long Tap Tap a row for an extended period of time to add/remove the row to/from selection.
Long Tap+Move Tap a row for an extended period and move the finger to add a range of rows to the current selection.

The TreeList component uses the key field’s values to identify and compare data items. If your data object has a primary key, assign it to the KeyFieldName property. Otherwise, the TreeList uses standard .NET value equality comparison to identify data items.

Multiple Row Selection

The TreeList allows users to select multiple rows simultaneously if the SelectionMode property is set to Multiple (the default value). Implement two-way binding for the SelectedDataItems property to specify and access data items that correspond to selected rows.

The following example allows users to click rows to select them and displays information about 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

Single Row Selection

Set the SelectionMode property to Single to allow users to select only one row at a time. Implement two-way binding for the SelectedDataItem property to specify and access the data item that corresponds to the selected row.

The following example allows users to click a row to select it and displays information about that row:

@inject EmployeeTaskService EmployeeTaskService

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

<div>
    <p><b>Selected task:</b> @((SelectedDataItem as EmployeeTask)?.Name ?? "(none)")</p>
</div>

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

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

Blazor TreeList Obtain Selected Data Item

Selection Column

You can also display a column that allows users to select and deselect rows. To do this, declare a DxTreeListSelectionColumn object in the Columns template. This column contains checkboxes in multiple selection mode and radio buttons in single selection mode. See the DxTreeListSelectionColumn class description for more information.

Selection in Code

You can call the Select* and Deselect* methods to add/remove rows to/from the selection. Refer to the TreeList’s member table for the list of available methods.

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

See Also