Locking Columns from Being Edited
You can prevent users from altering particular columns by setting a column's ReadOnly property to True.
In XAML
In the XAML below the ProductName column is added and is set to ReadOnly and so cannot be edited by users at run time:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Window1"
Title="Window1" Height="300" Width="300" xmlns:c1grid="clr-namespace:C1.WPF.C1DataGrid;assembly=C1.WPF.C1DataGrid">
<Grid>
<c1grid:C1DataGrid Name="C1DataGrid1" HorizontalAlignment="Left" VerticalAlignment="Top">
<c1grid:C1DataGrid.Columns>
<c1grid:Column Caption="Product Name" ColumnName="ProductName" ReadOnly="True"/>
</c1grid:C1DataGrid.Columns>
</c1grid:C1DataGrid>
</Grid>
</Window>
In Code
In the code below, the ProductName column is set to ReadOnly and so cannot be edited by users at run time:
C1DataGrid1.Columns("ProductName").ReadOnly = True
• C#
c1DataGrid1.Columns["ProductName"].ReadOnly = true;
|