Back to Devexpress

TableView.CanUnselectCell Event

wpf-devexpress-dot-xpf-dot-grid-dot-tableview-28dc0578.md

latest4.1 KB
Original Source

TableView.CanUnselectCell Event

Occurs in multiple cell selection mode when a user tries to unselect a grid cell and allows you to prevent this operation for a particular cell.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public event CanUnselectCellEventHandler CanUnselectCell
vb
Public Event CanUnselectCell As CanUnselectCellEventHandler

Event Data

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

PropertyDescription
CanUnselectCellGets or sets whether an end-user can unselect the processed cell.
ColumnGets a column to which the processed cell belongs.
RowGets a data row object that corresponds to the processed row (or treelist node).
RowHandleGets the handle of a row to which the processed cell belongs.
ViewGets a GridControl view to which the processed cell belongs.

Remarks

Handle the CanUnselectCell event to dynamically specify cells that users cannot unselect.

Set the CanUnselectCellEventArgs.CanUnselectCell property to false to keep the processed cell selected. Use the CanUnselectCellEventArgs.Row, CanUnselectCellEventArgs.RowHandle, and CanUnselectCellEventArgs.Column event argument properties to obtain the processed cell.

xaml
<dxg:GridControl ...
                 SelectionMode="Cell">
    <dxg:GridControl.View>
        <dxg:TableView ...
                       CanSelectCell="View_CanSelectCell"
                       CanUnselectCell="View_CanUnselectCell">
        </dxg:TableView>
    </dxg:GridControl.View>
</dxg:GridControl>
csharp
void View_CanSelectCell(object sender, CanSelectCellEventArgs e) {
    e.CanSelectCell = e.Column.FieldName != "Visits";
}
void View_CanUnselectCell(object sender, CanUnselectCellEventArgs e) {
    e.CanUnselectCell = e.Column.FieldName != "Birthday";
}
vb
Class SurroundingClass
    Private Sub View_CanSelectCell(ByVal sender As Object, ByVal e As CanSelectCellEventArgs)
        e.CanSelectCell = e.Column.FieldName <> "Visits"
    End Sub

    Private Sub View_CanUnselectCell(ByVal sender As Object, ByVal e As CanUnselectCellEventArgs)
        e.CanUnselectCell = e.Column.FieldName <> "Birthday"
    End Sub
End Class

Handle the TableView.CanSelectCell event to specify cells that users cannot select.

Refer to the following help topic for more information: Cell Selection.

See Also

CanUnselectRow

TableView Class

TableView Members

DevExpress.Xpf.Grid Namespace