60
votes

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?

3

3 Answers

106
votes

Set DataGrid's IsReadOnly property to true.

<DataGrid Grid.Row="1" Grid.Column="1" Name="Grid" ItemsSource="{Binding}"
    IsReadOnly="True" AutoGenerateColumns="False" >
4
votes

If you want to make the cells of a certain column readonly, you can set IsReadOnly for that column:

<DataGridTextColumn Header="Name" IsReadOnly="True" Width="100" Binding="{Binding Path=Name}"></DataGridTextColumn>
0
votes
    <DataGrid x:Name="dgUsers" 
    ...
    $dgUsers = $Form.FindName("dgUsers")
    ....
    # Make all columns cells readonly
    $dgUsers.Columns | ForEach-Object { $_.IsReadOnly = $True }