Version

Displaying Checkbox in Column Header

WinGrid™ has the ability to select the value for all cells within a particular Boolean column, via a checkbox placed in the column header. This provides the ability to automatically synchronize with all the cell values within the column. The functionality can be enabled through the HeaderCheckBoxVisibility , HeaderCheckBoxAlignment and HeaderCheckBoxSynchronization properties set through ultraGrid.DisplayLayout.Override object. Similarly using the properties CheckBoxVisibility , CheckBoxAlignment , CheckBoxSynchronization through the UltraGridColumn.Header object, checkboxes can be displayed in Column Headers.

The following code assumes WinGrid is bound to the Northwind Employees table. A Boolean column IsActive has been added to the Employees table for the sake of this topic.

In Visual Basic:

'Display a checkbox in the column header where the column's data type isBoolean, DefaultableBoolean, or Nullable Boolean.
Me.ultraGrid1.DisplayLayout. Bands(0).Columns("IsActive").Header.CheckBoxVisibility = HeaderCheckBoxVisibility.WhenUsingCheckEditor
'Aligns the Header checkbox to the right of the Header caption
Me.ultraGrid1.DisplayLayout.Bands(0).Columns("IsActive ").Header.CheckBoxAlignment = HeaderCheckBoxAlignment.Right
'The checkbox and the cell values are kept in synch to affect only the RowsCollection
Me.ultraGrid1.DisplayLayout.Bands(0).Columns("IsActive ").Header.CheckBoxSynchronization = HeaderCheckBoxSynchronization.RowsCollection

In C#:

//Display a checkbox in the column header, where column's data type isBoolean,DefaultableBoolean, or Nullable Boolean.
this.ultraGrid1.DisplayLayout. Bands[0].Columns["IsActive"].Header.CheckBoxVisibility = HeaderCheckBoxVisibility.WhenUsingCheckEditor;
//Aligns the Header checkbox to the right of the Header caption
this.ultraGrid1.DisplayLayout.Bands[0].Columns["IsActive"].Header.CheckBoxAlignment = HeaderCheckBoxAlignment.Right;
//The checkbox and the cell values are kept in synch to affect only the RowsCollection
this.ultraGrid1.DisplayLayout.Bands[0].Columns["IsActive"].Header.CheckBoxSynchronization = HeaderCheckBoxSynchronization.RowsCollection;
Wingrid Displaying Checkbox in Column header.png

Handling Events when check state is modified

The BeforeHeaderCheckStateChecked and the AfterHeaderCheckStateChecked events can be handled to performs tasks before or after the header check state is modified. The current header check state can be obtained through the UltraGridColumn object’s GetHeaderCheckedState method.

In Visual Basic:

Private Sub ultraGrid2_AfterHeaderCheckStateChanged(ByVal sender As Object, ByVal e As AfterHeaderCheckStateChangedEventArgs)
    Dim currentCheckState As CheckState = e.Column.GetHeaderCheckedState(e.Rows)
End Sub

In C#:

private void ultraGrid2_AfterHeaderCheckStateChanged(object sender, AfterHeaderCheckStateChangedEventArgs e)
        {
            CheckState currentCheckState = e.Column.GetHeaderCheckedState(e.Rows);
        }