KB Article A998
Visible to All Users

How to implement hot-tracking for grid rows

Description:
I would like to display a hand cursor and change the appearance of grid rows when the mouse is moved over them. Is this possible?

Answer:
In v2020.1 and newer, use the OptionsSelection.EnableAppearanceHotTrackedRow property to enable row hot-tracking.

In older versions, you can handle the MouseMove and RowCellStyle events as demonstrated below to implement row hot-tracking in your grid view.

C#
private int hotTrackRow = DevExpress.XtraGrid.GridControl.InvalidRowHandle; private int HotTrackRow { get { return hotTrackRow; } set { if (hotTrackRow != value) { int prevHotTrackRow = hotTrackRow; hotTrackRow = value; gridView1.RefreshRow(prevHotTrackRow); gridView1.RefreshRow(hotTrackRow); if (hotTrackRow >= 0) gridControl1.Cursor = Cursors.Hand; else gridControl1.Cursor = Cursors.Default; } } } private void gridView1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { GridView view = sender as GridView; GridHitInfo info = view.CalcHitInfo(new Point(e.X, e.Y)); if (info.InRowCell) HotTrackRow = info.RowHandle; else HotTrackRow = DevExpress.XtraGrid.GridControl.InvalidRowHandle; } private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e) { if (e.RowHandle == HotTrackRow) e.Appearance.BackColor = Color.PaleGoldenrod; }
Visual Basic
Imports DevExpress.XtraGrid Imports DevExpress.XtraGrid.Views.Grid Private HotTrackRowValue As Integer = GridControl.InvalidRowHandle Private Property HotTrackRow() As Integer     Get         Return HotTrackRowValue     End Get     Set(ByVal Value As Integer)         If HotTrackRowValue <> Value Then             Dim PrevHotTrackRow As Integer             PrevHotTrackRow = HotTrackRowValue             HotTrackRowValue = Value             GridView1.RefreshRow(PrevHotTrackRow)             GridView1.RefreshRow(HotTrackRowValue)             If HotTrackRowValue >= 0 Then                 GridControl1.Cursor = Cursors.Hand             Else                 GridControl1.Cursor = Cursors.Default             End If         End If     End Set End Property Private Sub GridView1_MouseMove(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles GridView1.MouseMove     Dim View As GridView = CType(sender, GridView)     With View.CalcHitInfo(New Point(e.X, e.Y))         If .InRowCell Then             HotTrackRow = .RowHandle         Else             HotTrackRow = GridControl.InvalidRowHandle         End If     End With End Sub Private Sub GridView1_RowCellStyle(ByVal sender As Object, ByVal e As RowCellStyleEventArgs) Handles GridView1.RowCellStyle     If e.RowHandle = HotTrackRow Then         e.Appearance.BackColor = Color.PaleGoldenrod     End If End Sub

See Also:
Customizing Appearances of Individual Rows
How to change the mouse cursor to a hand when the mouse moves over a hyperlink cell

Show previous comments (5)
DevExpress Support Team 11 years ago

    Hello Michael,
    I have created a separate thread on your behalf about this issue:
    Incorrect behavior when using the approach from the "How to implement hot-tracking for grid rows" example and RepositoryItemMemoExEdit
    We will update it soon.

      Hi,it is a good example
      I just edit one line and becomes very fantastic
       e.Appearance.BackColor = Me.BackColor
      this will take the hover background color of the row from the skin background color
      Thanks  alot for your support

      Nadezhda (DevExpress Support) 10 years ago

        Hello,

        Thank you very much for your review. We appreciate opinions of our customers.
        Do not hesitate to contact us if you need any further assistance.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.