Replace the default RowHeader triangle icon in WinForms Data Grid.
Replace the default rowheader triangle icon with another icon
By default, GridDataBoundGrid displays a triangle in the row header cell of the currently selected row. Refer to the following screenshot.
Solution
You can achieve this by changing the row header BaseStyleMap to Header and handling the PrepareViewStyleInfo events. In PrepareViewStyleInfo, you can also change the e.Style.Text (for text) or the e.Style.BackgroundImage (for images).
Refer to the following code example for changing BaseStyleMap.
C#
private void Form1_Load(object sender, System.EventArgs e) { this.gridDataBoundGrid1.BaseStylesMap["Row Header"].StyleInfo.CellType = "Header"; // BackgroundImageMode used to size to fit the image within the cell rectangle. this.gridDataBoundGrid1.BaseStylesMap["Row Header"].StyleInfo.BackgroundImageMode = GridBackgroundImageMode.StretchImage; this.gridDataBoundGrid1.PrepareViewStyleInfo += new Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventHandler(this.gridDataBoundGrid1_PrepareViewStyleInfo); }
VB
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.gridDataBoundGrid1.BaseStylesMap("Row Header").StyleInfo.CellType = "Header" Me.gridDataBoundGrid1.BaseStylesMap("Row Header").StyleInfo.BackgroundImageMode = GridBackgroundImageMode.StretchImage AddHandler gridDataBoundGrid1.PrepareViewStyleInfo, AddressOf gridDataBoundGrid1_PrepareViewStyleInfo End Sub
Refer to the following code example for changing text or image in PrepareViewStyleInfo.
C#
private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e) { if(e.ColIndex == 0 && this.gridDataBoundGrid1.CurrentCell.HasCurrentCellAt(e.RowIndex)) { e.Style.BackgroundImage = SystemIcons.Warning.ToBitmap(); } }
VB
Private Sub gridDataBoundGrid1_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs) Handles gridDataBoundGrid1.PrepareViewStyleInfo If e.ColIndex = 0 AndAlso Me.gridDataBoundGrid1.CurrentCell.HasCurrentCellAt(e.RowIndex) Then e.Style.BackgroundImage = SystemIcons.Asterisk.ToBitmap() End If End Sub
The following screenshot displays the RowHeader replaced with another image and text.
I hope you enjoyed learning about how to replace the default RowHeader triangle icon with another icon in WinForms GridControl or GridDataBoundGrid.
You can refer to our WinForms DataGrid feature tour page to know
about its other groundbreaking feature representations and documentation, and how to quickly get started
for configuration specifications. You can also explore our
WinForms DataGrid
example 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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!