I created a sample where I bound the ItemsSource DataGrid to an ObservableCollection, and here you have two options.
- Set AutoGenerateColumns = "False" to the DataGrid and set IsReadOnly = "True" for all columns except the column you want to edit, you set IsReadOnly = "False".
- AutoGenerateColumns = "True" (this is the default, so you can just remove the attribute from XAML) and make the setters private in your ViewModel for all properties except the column that you want to edit.
Here is my sample code for option 1:
<DataGrid x:Name="dgLoadDtl" Grid.Row="0" HorizontalAlignment="Left" VerticalAlignment="Top" ItemsSource="{Binding MyData}" AutoGenerateColumns="False"> <DataGrid.Columns> <DataGridTextColumn Foreground="Black" Width="60" Header="Sctn" Binding="{Binding Sctn, Mode=TwoWay}" IsReadOnly="false" /> <DataGridTextColumn Foreground="Black" Width="140" Header="CustName" Binding="{Binding CustName, Mode=TwoWay}" IsReadOnly="True"/> <DataGridTextColumn Foreground="Black" Width="140" Header="Address" Binding="{Binding Address1, Mode=TwoWay}" IsReadOnly="True"/> <DataGridTextColumn Foreground="Black" Width="50" Header="Bulk or Bag" Binding="{Binding BulkorBag, Mode=TwoWay}" IsReadOnly="True"/> <DataGridTextColumn Foreground="Black" Width="80" Header="ProdCode" Binding="{Binding ProdCode, Mode=TwoWay}" IsReadOnly="True"/> <DataGridTextColumn Foreground="Black" Width="80" Header="MedCode" Binding="{Binding MedCode, Mode=TwoWay}" IsReadOnly="True"/> </DataGrid.Columns> </DataGrid>
source share