Skip to main content Skip to footer

How to Display a Checkbox in FlexGrid Column Header in WPF

To place a checkbox in the header to acts an all on/off check, we can override the PrepareCell() method of GridCellFactory class to set the checkbox in the Column Header of the flexgrid as shown in the following code:

public override void PrepareCell(GridCellType cellType, GridCellRange range, GridCellView cell, Thickness internalBorders)
{
     base.PrepareCell(cellType, range, cell, internalBorders);
     if (cellType == GridCellType.ColumnHeader && range.Column == 2)
     {
         var checkBox = new CheckBox();
         checkBox.Content = "Check";                
         cell.Content = checkBox;
         cell.Content.VerticalAlignment = VerticalAlignment.Center;
         checkBox.Click += (s, e) =>
         {
              Grid.FinishEditing();
              foreach(var item in Grid.ItemsSource)
              {
                   ((UserDataItem)item).Check = (s as CheckBox).IsChecked;
              }
         };
     }
}