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 include an icon in the column header of the WinForms GridControl and GridDataBoundGrid?

Platform: WinForms |
Control: GridControl |
Published Date: April 30, 2011 |
Last Revised Date: February 10, 2020

Image index and list

When you use the ImageIndex and ImageList properties to set the icons, these properties only work for the TextBox and Static cells. So, make your header cell as static and then set your ImageIndex. For the DataBoundGrid, you have to use the PrepareViewStyleInfo to set these properties.

GridControl:

C#

private void Form1_Load(object sender, System.EventArgs e)
{
 this.gridControl1[0,2].CellType = "Static";
 this.gridControl1[0,2].Text = "B";
 this.gridControl1[0,2].CellAppearance = GridCellAppearance.Raised;
 this.gridControl1[0,2].ImageList = imageList;
 this.gridControl1[0,2].ImageIndex = 1;
}

VB

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
 Me.gridControl1(0,2).CellType = "Static"
 Me.gridControl1(0,2).Text = "B"
 Me.gridControl1(0,2).CellAppearance = GridCellAppearance.Raised
 Me.gridControl1(0,2).ImageList = imageList
 Me.gridControl1(0,2).ImageIndex = 1
End Sub

GridDataBoundGrid:

Refer to the following code example for setting the image in the header of the GridDataBoundGrid by using PrepareViewStyleInfo.

C#

private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e)
{
   if(e.RowIndex == 0 )
   {
      e.Style.CellType = "Static";
      e.Style.CellAppearance = GridCellAppearance.Raised;
      if(e.ColIndex == 1)
      {
         e.Style.ImageList = imageList;
         e.Style.ImageIndex = 0;
      }
      if(e.ColIndex == 2)
      {
         e.Style.ImageList = imageList;
         e.Style.ImageIndex = 1;
      }
      if(e.ColIndex == 3)
      {
         e.Style.ImageList = imageList;
         e.Style.ImageIndex = 2;
      }
   }
}

VB

Private Sub gridDataBoundGrid1_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs) Handles gridDataBoundGrid1.PrepareViewStyleInfo
  If e.RowIndex = 0 Then
     e.Style.CellType = "Static"
     e.Style.CellAppearance = GridCellAppearance.Raised
    If e.ColIndex = 1 Then
       e.Style.ImageList = imageList
       e.Style.ImageIndex = 0
    End If
    If e.ColIndex = 2 Then
       e.Style.ImageList = imageList
       e.Style.ImageIndex = 1
    End If
    If e.ColIndex = 3 Then
       e.Style.ImageList = imageList
       e.Style.ImageIndex = 2
    End If
  End If
End Sub

The following screenshots display the images in the header of the GridControl and GridDataBoundGrid.

Show the images in column header

Samples:

C#: ColumnHeaderIcon CS

VB: ColumnHeaderIcon VB

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