user3793783
user3793783

Reputation: 71

C# WPF - Cannot check/uncheck checkbox in DataGridCheckBoxColumn

I´m initializing the DataGrid in XAML but the Columns are generated in the code because columns are varying based on the input data. However when DataGridCheckBoxColumn is generated I cannot check/uncheck the single checkbox in any row of this column. Some of them are checked/unchecked based on the value of bool "checkFlag"

DataGridCheckBoxColumn checkColumn = new DataGridCheckBoxColumn();
checkColumn.Header = "Save";
checkColumn.Binding = new Binding("checkFlag");
checkColumn.MinWidth = 50;
vysledkyDataGrid.Columns.Add(checkColumn);

<DataGrid AutoGenerateColumns="false" 
          Margin="20,247,25,94" 
          Name="vysledkyDataGrid"
          IsEnabled="True" 
          CanUserReorderColumns="False" 
          CanUserResizeColumns="True" 
          CanUserSortColumns="False" 
          HorizontalGridLinesBrush="DarkGray"              
          VerticalGridLinesBrush="DarkGray" 
          ClipboardCopyMode="None" 
          IsReadOnly="True">
        <DataGrid.ColumnHeaderStyle>
            <Style TargetType="{x:Type DataGridColumnHeader}">
                <Setter Property="HorizontalAlignment" Value="Stretch" />
                <Setter Property="HorizontalContentAlignment" Value="Center" />
            </Style>
        </DataGrid.ColumnHeaderStyle>
        <DataGrid.CellStyle>
            <Style TargetType="DataGridCell">
                <Setter Property="Block.TextAlignment" Value="Right"/>
            </Style>
        </DataGrid.CellStyle>
    </DataGrid>

Upvotes: 4

Views: 5429

Answers (1)

Alexander Bell
Alexander Bell

Reputation: 7918

Your DataGrid has a property ReadOnly = true. You have to set it to ReadOnly = false to make it editable,so you would be able to check/uncheck the CheckBox. Regards

Upvotes: 10

Related Questions