Articles in this section
Category / Section

How to set the current row bold in WinForms GridControl?

2 mins read

Change the font style

The current row data can be changed to Bold font style by using the PrepareViewStyleInfo event. Using this event, the style can be changed by validating whether CurrentCell is in WinForms Grid Control. But the current row range has to be refreshed while activating the cell and deactivating the cells.

C#

//Form()
gridControl1.CurrentCellActivated += gridControl1_CurrentCellActivated;
gridControl1.CurrentCellDeactivated += gridControl1_CurrentCellDeactivated;
gridControl1.PrepareViewStyleInfo += gridControl1_PrepareViewStyleInfo;
 
void gridControl1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
   GridControlBase grid = gridControl1;
   GridCurrentCell cc = gridControl1.CurrentCell;
   if (e.RowIndex > grid.Model.Rows.HeaderCount && e.ColIndex > grid.Model.Cols.HeaderCount && cc.HasCurrentCellAt(e.RowIndex))
   {
      e.Style.Font.Bold = true;
   } 
}
 
void gridControl1_CurrentCellDeactivated(object sender, GridCurrentCellDeactivatedEventArgs e)
{
   GridControlBase grid = gridControl1;
   GridCurrentCell cc = gridControl1.CurrentCell;
   //Checks if Deactivate is called stand-alone or called from MoveTo and the row is moving.     
   if (!cc.IsInMoveTo || cc.MoveToRowIndex != cc.MoveFromRowIndex)
   {
      grid.RefreshRange(GridRangeInfo.Row(e.RowIndex), GridRangeOptions.MergeAllSpannedCells);
   }
}
 
void gridControl1_CurrentCellActivated(object sender, EventArgs e)
{
   GridControlBase grid = gridControl1;
   GridCurrentCell cc = gridControl1.CurrentCell;
   //Checks if Activate is called stand-alone or called from MoveTo and the row is moving.     
   if (!cc.IsInMoveTo || cc.MoveToRowIndex != cc.MoveFromRowIndex
      || !cc.MoveFromActiveState)
   {
      grid.RefreshRange(GridRangeInfo.Row(cc.RowIndex), GridRangeOptions.MergeAllSpannedCells);
   }
}

 

VB

‘Form()
Private gridControl1.CurrentCellActivated += AddressOf gridControl1_CurrentCellActivated
Private gridControl1.CurrentCellDeactivated += AddressOf gridControl1_CurrentCellDeactivated
Private gridControl1.PrepareViewStyleInfo += AddressOf gridControl1_PrepareViewStyleInfo
 
Private Sub gridControl1_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As GridPrepareViewStyleInfoEventArgs)
 Dim grid As GridControlBase = gridControl1
 Dim cc As GridCurrentCell = gridControl1.CurrentCell
 If e.RowIndex > grid.Model.Rows.HeaderCount AndAlso e.ColIndex > grid.Model.Cols.HeaderCount AndAlso cc.HasCurrentCellAt(e.RowIndex) Then
  e.Style.Font.Bold = True
 End If
End Sub
 
Private Sub gridControl1_CurrentCellDeactivated(ByVal sender As Object, ByVal e As GridCurrentCellDeactivatedEventArgs)
 Dim grid As GridControlBase = gridControl1
 Dim cc As GridCurrentCell = gridControl1.CurrentCell
 'Checks if Deactivate is called stand-alone or called from MoveTo and the row is moving.     
 If (Not cc.IsInMoveTo) OrElse cc.MoveToRowIndex <> cc.MoveFromRowIndex Then
  grid.RefreshRange(GridRangeInfo.Row(e.RowIndex), GridRangeOptions.MergeAllSpannedCells)
 End If
End Sub
 
Private Sub gridControl1_CurrentCellActivated(ByVal sender As Object, ByVal e As EventArgs)
 Dim grid As GridControlBase = gridControl1
 Dim cc As GridCurrentCell = gridControl1.CurrentCell
 'Checks if Activate is called stand-alone or called from MoveTo and the row is moving.     
 If (Not cc.IsInMoveTo) OrElse cc.MoveToRowIndex <> cc.MoveFromRowIndex OrElse (Not cc.MoveFromActiveState) Then
  grid.RefreshRange(GridRangeInfo.Row(cc.RowIndex), GridRangeOptions.MergeAllSpannedCells)
 End If
End Sub

Screenshot

Change font style to current row in WinForms Grid Control

Samples:

C#: Current_Row_FontStyle_CS

VB: Current_Row_FontStyle_VB

Conclusion

I hope you enjoyed learning about how to set the current row bold in WinForms GridControl.

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

For current customers, you can check out our WinForms from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms Grid Control and other WinForms components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-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