Articles in this section
Category / Section

How to set backcolor for group header in WinForms GridGroupingControl?

1 min read

Change the backcolor for group header cell

You can change the backColor for each group header cell, based on the content in the WinForms  GridGroupingControl by using QueryCellStyleInfo event. In this event, you can check the celltype as GroupCaptioncell and also apply the color for SummaryCell based on the content.

C#

// Form load
// to apply the summary color for 1st level 
this.gridGroupingControl1.Appearance.AnySummaryCell.BackColor = Color.FromArgb(255, 231, 162); 
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
   if(e.TableCellIdentity.TableCellType == GridTableCellType.GroupCaptionCell)
   {
      // content text and 1st level
      if(e.Style.Text == "1 Items" && e.TableCellIdentity.DisplayElement.ChildTableGroupLevel==1)
      {
         e.Style.BackColor = Color.FromArgb(255, 231, 162);
      }
      // 2nd level groupedcolumn
      else if (e.TableCellIdentity.DisplayElement.ChildTableGroupLevel == 2)
      {
         e.Style.BackColor = Color.LightGreen;
      }
   }
   // apply the summary color for level 2
   if(e.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.Summary && e.TableCellIdentity.DisplayElement.ChildTableGroupLevel == 2)          
   {
      e.Style.BackColor = Color.LightGreen;
   }
}

VB

' Form load
‘ to apply the summary color for 1st level 
Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs)
   If e.TableCellIdentity.TableCellType = GridTableCellType.GroupCaptionCell Then
      ' content text and 1st level
      If e.Style.Text = "1 Items" AndAlso e.TableCellIdentity.DisplayElement.ChildTableGroupLevel=1 Then 
         e.Style.BackColor = Color.FromArgb(255, 231, 162)
      ' 2nd level groupedcolumn
      ElseIf e.TableCellIdentity.DisplayElement.ChildTableGroupLevel = 2 Then
         e.Style.BackColor = Color.LightGreen
      End If
   End If
   ' apply the summary color for level 2
   If e.TableCellIdentity.DisplayElement.Kind = DisplayElementKind.Summary AndAlso
      e.TableCellIdentity.DisplayElement.ChildTableGroupLevel = 2 Then 
      e.Style.BackColor = Color.LightGreen
   End If
End Sub

The following screenshot displays the Backcolor for GroupHeaderCell and SummaryCell.

Backcolor for groupheadercell and summary cell

Figure 1: Backcolor for GroupHeaderCell and SummaryCell

Samples: https://www.syncfusion.com/downloads/support/directtrac/general/Color_GroupHeaderCell809696102.zip


Conclusion

I hope you enjoyed learning about how to set the backcolor for group header cell based on the content in WinForms GridGroupingControl.

You can refer to our  WinForms GridGroupingControl feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridGroupingControl documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

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