Articles in this section
Category / Section

How to include icon column header of WinForms Grid?

2 mins read

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



Conclusion

I hope you enjoyed learning about How to include an icon in the column header of the WinForms GridControl and GridDataBoundGrid.

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

For current customers, you can check out our WinForms 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 ASP.NET MVC Chart and other ASP.NET MVC components.

If you have any queries or require clarifications, please let us know in comments 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