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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: WinForms |
Control: GridGroupingControl
Tags: row, color, mousehover

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!

 

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