I use the following DataGrid
<DataGrid Grid.Row="1" Grid.Column="1" Name="Grid" ItemsSource="{Binding}" AutoGenerateColumns="False" > <DataGrid.Columns> <DataGridTextColumn Header="Name" Width="100" Binding="{Binding Path=Name}"></DataGridTextColumn> <DataGridTextColumn Header="OldValue" Width="100" Binding="{Binding Path=OldValue}"></DataGridTextColumn> <DataGridTextColumn Header="NewValue" Width="100*" Binding="{Binding Path=NewValue}"></DataGridTextColumn> </DataGrid.Columns> </DataGrid>
How can I make the cells readonly?
You can easily use IsReadOnly property on the DataGrid to make it entirely read only. or use IsReadOnly per Column basis to make them read only. The WPF DataGrid has an IsReadOnly property that you can set to True to ensure that users cannot edit your DataGrid 's cells.
To make individual columns or cells read-only, set the DataGridColumn. IsReadOnly or DataGridCell. IsReadOnly properties. If a conflict exists between the settings at the DataGrid, column, or cell levels, a value of true takes precedence over a value of false .
In the DataGridViewcontrol, the column ReadOnlyproperty value determines whether users can edit cells in that column. For information about how to make the control entirely read-only, see How to: Prevent Row Addition and Deletion in the Windows Forms DataGridView Control.
In v 19.2 and newer versions, Grid Control supports the Disabled Cell Behavior that allows you to disable individual grid cells and customize their appearance with ease. To make a grid cell read-only, handle the ShowingEditor event and set the e.Cancel parameter to true.
In this article Not all data is meant for editing. In the DataGridViewcontrol, the column ReadOnlyproperty value determines whether users can edit cells in that column. For information about how to make the control entirely read-only, see How to: Prevent Row Addition and Deletion in the Windows Forms DataGridView Control.
I understand you can make the whole DataGrid or a whole column readyonly (IsReadOnly = true). However, at cell level this property is ready only. But I do need this level of granularity.
Set DataGrid's IsReadOnly property to true.
<DataGrid Grid.Row="1" Grid.Column="1" Name="Grid" ItemsSource="{Binding}" IsReadOnly="True" AutoGenerateColumns="False" >
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With