Skip to content

SyncfusionExamples/how-to-change-state-of-header-checkbox-in-grid-check-box-columnn-programmatically-in-winforms-data-g

Repository files navigation

How to Change State of Header Checkbox in GridCheckBoxColumnn Programmatically in WinForms DataGrid?

This sample illustrates how to change state of header checkbox in GridCheckBoxColumnn Programmatically in WinForms DataGrid (SfDataGrid).

In DataGrid, 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 WinForms DataGrid - GridCheckBoxColumn, where you can find about GridCheckBoxColumn, with code examples.

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5

Languages