We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to set the header cell color for the WinForms GridControl?

Platform: WinForms |
Control: GridControl

Applied header cell color

You can change the color of the particular header cell in a Grid control by setting its BackColor property. You can achieve this by using the PrepareViewStyleInfo event handler. And also by using the ChangeCells() method, you can change the BackColor property for the particular range of cells.

Using PrepareViewStyleInfo Event


//Hook the event to change the back color for the header cells.
this.gridControl1.PrepareViewStyleInfo += gridControl1_PrepareViewStyleInfo;
void gridControl1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
   if (e.RowIndex == 0)
      if (e.ColIndex == 1)
         e.Style.BackColor = Color.LightBlue;
      if (e.ColIndex == 2)
         e.Style.BackColor = Color.LightGreen;
      if (e.ColIndex == 3)
         e.Style.BackColor = Color.LightPink;
      if (e.ColIndex == 4)
         e.Style.BackColor = Color.LightGray;


'Hook the event to change the back color for the header cells.
Private Me.gridControl1.PrepareViewStyleInfo += AddressOf gridControl1_PrepareViewStyleInfo
Private Sub gridControl1_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As GridPrepareViewStyleInfoEventArgs)
   If e.RowIndex = 0 Then
      If e.ColIndex = 1 Then
        e.Style.BackColor = Color.LightBlue
      End If
      If e.ColIndex = 2 Then
        e.Style.BackColor = Color.LightGreen
      End If
      If e.ColIndex = 3 Then
        e.Style.BackColor = Color.LightPink
      End If
      If e.ColIndex = 4 Then
        e.Style.BackColor = Color.LightGray
      End If
   End If
End Sub

Using ChangeCells() method


GridStyleInfo style = this.gridControl1[0, 0];
style.BackColor = Color.Pink;
//Change the Header color usign style object
this.gridControl1.ChangeCells(GridRangeInfo.Cells(0, 5, 0, 8), style);


Dim style As GridStyleInfo = Me.gridControl1(0, 0)
style.BackColor = Color.Pink
'Change the Header color usign style object
Me.gridControl1.ChangeCells(GridRangeInfo.Cells(0, 5, 0, 8), style)

The following screenshot illustrates the output.

Applied header color

Figure 1: Applied Header Color


C#: SetHeaderColorForPerticularCell

VB: SetHeaderColorForPerticularCell

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile