Articles in this section
Category / Section

How to change the row color on mouse hover in WinForms GridGroupingControl?

2 mins read

This article explains how to change the row color on mouse hover in WinForms GridControl.

Change the row color

By default, the current record will be highlighted if record is selected. If you want to change the row color while hovering the mouse, it can be achieved by handling the TableControlCellMouseHoverEnter, TableControlCellMouseHoverLeave and QueryCellStyleInfo events. Refer the below code snippet,

C#

//Invoke the events to change the color of row during the mouse hover.
this.gridGroupingControl1.TableControlCellMouseHoverEnter += gridGroupingControl1_TableControlCellMouseHoverEnter;
this.gridGroupingControl1.QueryCellStyleInfo += gridGroupingControl1_QueryCellStyleInfo;
 
void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)
{
    if (hoveredIndex == e.TableCellIdentity.RowIndex)
    {
        //Set the back color for the mouse hovered row.
        e.Style.BackColor = Color.LightBlue;
    }
}
 
void gridGroupingControl1_TableControlCellMouseHoverEnter(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCellMouseEventArgs e)
{
    //Set the hovered row index to change the backcolor.
    hoveredIndex = e.Inner.RowIndex;
    this.gridGroupingControl1.TableControl.Refresh();
}            

 

VB

'Invoke the events to change the color of row during the mouse hover.
Me.gridGroupingControl1.TableControlCellMouseHoverEnter += gridGroupingControl1_TableControlCellMouseHoverEnter
Me.gridGroupingControl1.QueryCellStyleInfo += gridGroupingControl1_QueryCellStyleInfo
 
Dim hoveredIndex As Integer =-1
 
Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs)
   If hoveredIndex = e.TableCellIdentity.RowIndex Then
      'Set the back color for the mouse hoverd row.
      e.Style.BackColor = Color.LightBlue
   End If
End Sub
 
Private Sub gridGroupingControl1_TableControlCellMouseHoverEnter(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlCellMouseEventArgs)
   'Set the hovered row index to change the backcolor.
   hoveredIndex = e.Inner.RowIndex
   Me.gridGroupingControl1.TableControl.Refresh()
End Sub

 

Screenshot

Change the row color while hovering the mouse on the row in WinForms Grid Control

Samples:

C#: MouseHover_CS

VB: MouseHover_VB

Conclusion

I hope you enjoyed learning about how to change the row color on mouse hover in WinForms GridGroupingControl

You can refer to our  WinForms Grid Control’s feature tour page to know about its other groundbreaking feature representations.

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