)
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 set the current row bold in WinForms GridControl?

Platform: WinForms |
Control: GridControl |
Published Date: January 3, 2016 |
Last Revised Date: December 18, 2019
Tags: styling

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 grid. 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

Samples:

C#: Current_Row_FontStyle_CS

VB: Current_Row_FontStyle_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