Articles in this section
Category / Section

How to change state of header checkbox in GridCheckBoxColumnn Programmatically in WinForms DataGrid?

1 min read

In WinForms DataGrid (SfDataGrid), checkbox in the header cell of the GridCheckBoxColumn can be checked/unchecked by manually clicking on the checkbox in the header or by checking/unchecking the checkboxes in all the record cells. You can also change the checkbox state of the header cell of the GridCheckBoxColumn programmatically.

 

var headerState = (CheckState)(this.sfDataGrid1.Columns["IsClosed"] as GridCheckBoxColumn).GetType().GetProperty("HeaderState", System.Reflection.BindingFlags.Instance
    | System.Reflection.BindingFlags.NonPublic).GetValue(this.sfDataGrid1.Columns["IsClosed"] as GridCheckBoxColumn);
 
if (headerState == CheckState.Checked)
{
    (this.sfDataGrid1.Columns["IsClosed"] as GridCheckBoxColumn).GetType().GetProperty("HeaderState", System.Reflection.BindingFlags.Instance 
        | System.Reflection.BindingFlags.NonPublic).SetValue(this.sfDataGrid1.Columns["IsClosed"] as GridCheckBoxColumn, CheckState.Unchecked);
 
    foreach(var item in orderInfo.OrdersListDetails)
    {
        item.IsClosed = false;
    }
}
else if (headerState == CheckState.Unchecked)
{
    (this.sfDataGrid1.Columns["IsClosed"] as GridCheckBoxColumn).GetType().GetProperty("HeaderState", System.Reflection.BindingFlags.Instance 
        | System.Reflection.BindingFlags.NonPublic).SetValue(this.sfDataGrid1.Columns["IsClosed"] as GridCheckBoxColumn, CheckState.Checked);
 
    foreach (var item in orderInfo.OrdersListDetails)
    {
        item.IsClosed = true;
    }
}

 

Take a moment to peruse the documentation, where you can find about GridCheckBoxColumn, with code examples.

Please refer this link to know about the essential features of Syncfusion WPF DataGrid.

You can download the example from GitHub

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied