Wallnut
Wallnut

Reputation: 157

wpf/c#: creating a datagrid which is partly read-only and partly editable

I want to create a DataGrid of four rows (fixed) and a variable number of columns (between six and ten). Two of the rows need to be editable in all columns, the remaining two need to be read-only except for one column (differentiated by the value of a variable) which needs to be editable on all rows. I can make this column editable while the rest of the DataGrid is read-only easily enough, but this problem is more complex than that. I'm fairly new to WPF so any answers involving XAML code need to be explained so that a novice can understand!

Upvotes: 0

Views: 136

Answers (1)

Celso Lívero
Celso Lívero

Reputation: 726

Set IsReadOnly True or False for each column individually

Edit: but this would not work for each Row individually, in which case it would give a little more work, this question/answer will help you

<DataGrid ColumnWidth="*" 
          AutoGenerateColumns="False" 
          SelectionMode="Single" 
          HorizontalContentAlignment="Center" 
          ItemsSource="{Binding DataGridItems}" 
          ScrollViewer.CanContentScroll="True" 
          ScrollViewer.VerticalScrollBarVisibility="Auto" 
          ScrollViewer.HorizontalScrollBarVisibility="Auto" >
    <DataGrid.Columns>
        <DataGridTextColumn .... IsReadOnly="True"/>
        <DataGridTextColumn .... IsReadOnly="True"/>
        <DataGridTextColumn .... IsReadOnly="False"/>
    </DataGrid.Columns>
</DataGrid>

Upvotes: 2

Related Questions