Make Cells Read-only or Disable Editing
- 3 minutes to read
Users cannot edit read-only cells. They can only invoke cell editors to select and copy their values.
If cells are disabled, users cannot invoke cell editors.
Make Cells Read-only
Make an Individual Column Read-only
Set the column’s ReadOnly property to true
.
<dxg:GridControl ItemsSource="{Binding Items}">
<dxg:GridColumn FieldName="Id" ReadOnly="True" />
<dxg:GridColumn FieldName="Name" />
</dxg:GridControl>
Make the Entire Grid Read-only
Apply a common style to all columns to make columns read-only. In the style, set the ColumnBase.ReadOnly property to true
.
<Window.Resources>
<Style TargetType="dxg:GridColumn">
<Setter Property="ReadOnly" Value="True" />
</Style>
</Window.Resources>
<dxg:GridControl AutoGenerateColumns="AddNew" ItemsSource="{Binding Items}" />
Make Individual Rows/Cells Read-only
To make cells read-only based on another value, specify the BaseColumn.IsReadOnlyBinding property as follows:
<dxg:GridControl ItemsSource="{Binding Items}">
<dxg:GridColumn FieldName="Name" IsReadOnlyBinding="{Binding YourBooleanProperty}" />
</dxg:GridControl>
In versions prior to v20.2, use the BaseEdit.IsReadOnly property in the ColumnBase.CellTemplate or ColumnBase.CellTemplateSelector property.
<dxg:GridColumn FieldName="Name">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<dxe:TextEdit Name="PART_Editor" IsReadOnly="{Binding RowData.Row.YourBooleanProperty}" />
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
Note
The only supported method to set the IsReadOnly
property in a ColumnBase.CellTemplate is binding. Do not use a setter to specify the IsReadOnly
property.
Disable Editing
Disable Editing in an Individual Column
Set the column’s AllowEditing property to false
.
<dxg:GridControl ItemsSource="{Binding Items}">
<dxg:GridColumn FieldName="Id" AllowEditing="False" />
</dxg:GridControl>
Alternatively, you can set the column’s AllowFocus property to false
to prevent the column from being focused. As a result, users cannot edit cells in this column.
<dxg:GridControl ItemsSource="{Binding Items}">
<dxg:GridColumn FieldName="Id" AllowFocus="False" />
</dxg:GridControl>
Disable Editing in the Entire Grid
Set the DataViewBase.AllowEditing property to false
. To enable editing for individual columns, set their AllowEditing properties to true
.
<dxg:GridControl AutoGenerateColumns="AddNew" ItemsSource="{Binding Items}">
<dxg:GridColumn FieldName="Id" />
<dxg:GridColumn FieldName="Name" AllowEditing="True" /> <!-- this column is editable -->
<dxg:GridControl.View>
<dxg:TableView AllowEditing="False" />
</dxg:GridControl.View>
</dxg:GridControl>
Alternatively, set the DataViewBase.NavigationStyle property to Row
or None
to prevent individual cells from being selected. Setting the ColumnBase.AllowEditing property to true
has no effect in this case.
<dxg:GridControl ItemsSource="{Binding Items}">
<dxg:GridColumn FieldName="Id" />
<dxg:GridColumn FieldName="Name" AllowEditing="True" /> <!-- ignored -->
<dxg:GridControl.View>
<dxg:TableView NavigationStyle="Row" />
</dxg:GridControl.View>
</dxg:GridControl>
Disable Editing for Individual Rows/Cells
To disable editing based on another value, specify the BaseColumn.IsEnabledBinding property as follows:
<dxg:GridControl ItemsSource="{Binding Items}">
<dxg:GridColumn FieldName="Name" IsEnabledBinding="{Binding YourBooleanProperty}" />
</dxg:GridControl>
In versions prior to v20.2, use the GridViewBase.ShowingEditor or TreeListView.ShowingEditor event.