Skip to main content

DataViewBase.CanSelectRow Event

Occurs in multiple row select mode when an end-user tries to select a grid row (node) and allows you to prevent selecting a particular row (node).

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v24.1.Core.dll

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public event CanSelectRowEventHandler CanSelectRow

Event Data

The CanSelectRow event's data class is CanSelectRowEventArgs. The following properties provide information specific to this event:

Property Description
CanSelectRow Gets or sets whether an end-user can select the processed row.
Row Gets a data row object that corresponds to the processed row (or treelist node).
RowHandle Gets the handle of a processed row.
View Gets a GridControl view to which the processed row belongs.

Remarks

Handle the CanSelectRow event to dynamically prevent users from selecting particular rows.

Set the event argument’s CanSelectRowEventArgs.CanSelectRow property to false to prevent a user from selecting a processed row. Use the CanSelectRowEventArgs.Row and CanSelectRowEventArgs.RowHandle event argument properties to retrieve a processed row.

<dxg:GridControl ... 
                 SelectionMode="Row">
    <dxg:GridControl.View>
        <dxg:TableView ...
                       CanSelectRow="tableView_CanSelectRow"/>
    </dxg:GridControl.View>
</dxg:GridControl>
private void tableView_CanSelectRow(object sender, DevExpress.Xpf.Grid.CanSelectRowEventArgs e) {
    if (((Item)e.Row).Name == "John") {
        e.CanSelectRow = false;
    }
}

Handle the DataViewBase.CanUnselectRow event to prevent end-users from unselecting a particular row.

Select a Cell

Handle the TableView.CanSelectCell (TreeListView.CanSelectCell for the TreeListView) event to prevent users from selecting a particular cell.

See Also