2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
This article explains how to change the row color on mouse hover in WinForms GridControl. Change the row colorBy 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 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.
This page will automatically be redirected to the sign-in page in 10 seconds.