How to highlight current row cell in WinForms GridControl?
Highlights the selected row
This can be done by handling the PrepareViewStyleInfo event and by changing the text color and the backcolor of the selected ranges of cells in WinForms GridControl.
C#
void gridControl1_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e) { GridControlBase grid = gridControl1; GridCurrentCell cc = gridControl1.CurrentCell; // Highlight the current row with SystemColors.Highlight and bold font if(e.RowIndex > grid.Model.Rows.HeaderCount && e.ColIndex > grid.Model.Cols.HeaderCount && cc.HasCurrentCellAt(e.RowIndex)) { e.Style.Interior = new BrushInfo(SystemColors.Highlight); e.Style.TextColor = SystemColors.HighlightText; e.Style.Font.Bold = true; } }
VB
Private Sub gridControl1_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs) Dim grid As GridControlBase = gridControl1 Dim cc As GridCurrentCell = gridControl1.CurrentCell ' Highlight the current row with SystemColors.Highlight and bold font If e.RowIndex > grid.Model.Rows.HeaderCount AndAlso e.ColIndex > grid.Model.Cols.HeaderCount AndAlso cc.HasCurrentCellAt(e.RowIndex) Then e.Style.Interior = New BrushInfo(SystemColors.Highlight) e.Style.TextColor = SystemColors.HighlightText e.Style.Font.Bold = True End If End Sub
After applying the properties, the grid is shown as follows.
Figure 1: Highlighted the current row including current cell
Samples:
C#: HighLightRow
VB: HighLightRow
Conclusion
I hope you enjoyed learning how to highlight current row cell in WinForms GridControl.
You can refer to WinForms Grid 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 Grid 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!