)
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. (Last updated on: June 24, 2019).
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 |
Published Date: April 21, 2015 |
Last Revised Date: December 18, 2019

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

C#

//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;
      }
   }
}

VB

'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

C#

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);

VB

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

Samples:

C#: SetHeaderColorForPerticularCell

VB: SetHeaderColorForPerticularCell

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
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
Live Chat Icon