我使用以下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>
如何让细胞只读?
答案 0 :(得分:89)
将DataGrid的IsReadOnly属性设置为true。
<DataGrid Grid.Row="1" Grid.Column="1" Name="Grid" ItemsSource="{Binding}"
IsReadOnly="True" AutoGenerateColumns="False" >
答案 1 :(得分:0)
如果要将某些列的单元格设为只读,则可以为该列设置IsReadOnly:
<DataGridTextColumn Header="Name" IsReadOnly="True" Width="100" Binding="{Binding Path=Name}"></DataGridTextColumn>
答案 2 :(得分:0)
<DataGrid x:Name="dgUsers"
...
$dgUsers = $Form.FindName("dgUsers")
....
# Make all columns cells readonly
$dgUsers.Columns | ForEach-Object { $_.IsReadOnly = $True }