wpf-devexpress-dot-xpf-dot-grid-dot-tableview-aabc63f5.md
Occurs in multiple cell selection mode when a user tries to select a grid cell and allows you to prevent the cell selection.
Namespace : DevExpress.Xpf.Grid
Assembly : DevExpress.Xpf.Grid.v25.2.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public event CanSelectCellEventHandler CanSelectCell
Public Event CanSelectCell As CanSelectCellEventHandler
The CanSelectCell event's data class is CanSelectCellEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| CanSelectCell | Gets or sets whether an end-user can select the processed cell. |
| Column | Gets a column to which the processed cell belongs. |
| Row | Gets a data row object that corresponds to the processed cell. |
| RowHandle | Gets the handle of a row to which the processed cell belongs. |
| View | Gets a GridControl view to which the processed cell belongs. |
Handle the CanSelectCell event to dynamically specify cells that users cannot select.
Set the CanSelectCellEventArgs.CanSelectCell property to false to prevent the cell selection. Use the CanSelectCellEventArgs.Row, CanSelectCellEventArgs.RowHandle, and CanSelectCellEventArgs.Column event argument properties to obtain the processed cell.
<dxg:GridControl ...
SelectionMode="Cell">
<dxg:GridControl.View>
<dxg:TableView ...
CanSelectCell="View_CanSelectCell"
CanUnselectCell="View_CanUnselectCell">
</dxg:TableView>
</dxg:GridControl.View>
</dxg:GridControl>
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";
}
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.CanUnselectCell event to specify cells that users cannot unselect.
Refer to the following help topic for more information: Cell Selection.
See Also