Articles in this section
Category / Section

How to keep the same background style in WinForms GridGroupingControl?

2 mins read

Header style

When you set the cell type of the column header as Checkbox, the header style changes.

Solution:

The GetGridstyleInfo() method has to be used to keep the same background color of the header cell while changing the header cell type. The required customization is done in this GetGridStylenfo() method. You have to use the QuerycellstyleInfo event to get the style and then pass this style to the GetGridstyleInfo() method.

C#

// QueryCellStyleInfo event.
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
   if(e.TableCellIdentity.TableCellType == GridTableCellType.ColumnHeaderCell && e.TableCellIdentity.Column.Name == "Property1")
   {
      // set the celltype as checkbox in column 1.
      e.Style.CellType = GridCellTypeName.CheckBox;
      e.Style.Description = e.Style.Text;
      e.Style.CellValueType = typeof(bool);
      e.Style.CellValue = true;
      // to apply the style of grid.
      e.Style.Interior = GetThemeInterior(e.Style);
   }
}
// to fill the grid background color(GetGridstyleInfo).
private BrushInfo GetThemeInterior(GridStyleInfo style)
{
   // apply the color for theme.
   GridVisualStyles visualStyles = this.gridGroupingControl1.TableModel.Options.GridVisualStyles;
   switch (visualStyles)
   {
      case GridVisualStyles.Office2007Blue:
              return new BrushInfo(GradientStyle.Vertical, Color.FromArgb(249, 252, 255), Color.FromArgb(197, 222, 255));
      case GridVisualStyles.Office2010Silver:
             return new BrushInfo(GradientStyle.Vertical, Color.FromArgb(223, 227, 232), Color.FromArgb(183, 188, 193));
      default:
             style.TextColor = Color.Black;
             return new BrushInfo(GradientStyle.Vertical, Color.FromArgb(249, 252, 255), Color.FromArgb(197, 222, 255));
   }
}

VB

' QueryCellStyleInfo event.
Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs)
   If e.TableCellIdentity.TableCellType = GridTableCellType.ColumnHeaderCell AndAlso e.TableCellIdentity.Column.Name = "Property1" Then
      ' set the celltype as checkbox in column 1.
      e.Style.CellType = GridCellTypeName.CheckBox
      e.Style.Description = e.Style.Text
      e.Style.CellValueType = GetType(Boolean)
      e.Style.CellValue = True
      ' to apply the style of grid.
      e.Style.Interior = GetThemeInterior(e.Style)
   End If
End Sub
' to fill the grid background color(GetGridstyleInfo).
Private Function GetThemeInterior(ByVal style As GridStyleInfo) As BrushInfo
   ' apply the color for theme.
   Dim visualStyles As GridVisualStyles = Me.gridGroupingControl1.TableModel.Options.GridVisualStyles
   Select Case visualStyles
      Case GridVisualStyles.Office2007Blue
               Return New BrushInfo(GradientStyle.Vertical, Color.FromArgb(249, 252, 255), Color.FromArgb(197, 222, 255))
      Case GridVisualStyles.Office2010Silver
               Return New BrushInfo(GradientStyle.Vertical, Color.FromArgb(223, 227, 232), Color.FromArgb(183, 188, 193))
      Case Else
               style.TextColor = Color.Black
               Return New BrushInfo(GradientStyle.Vertical, Color.FromArgb(249, 252, 255), Color.FromArgb(197, 222, 255))
   End Select

 

Note:

To learn how to use the checkbox and other functions, refer to the following link:

http://www.syncfusion.com/kb/3954

Samples:

C#: Header style

VB: Header style

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