Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 662
user3793783 Avatar asked Oct 27 '25 10:10

user3793783


1 Answers

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

like image 140
Alexander Bell Avatar answered Oct 28 '25 23:10

Alexander Bell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!