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 BasicImports 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
Hi Nick,
Thanks for the prompt reply. Your solution works very well, but it highlights the entire row. How can I edit it to make it paint only the cell?
Hi Serdar,
I have created a Support Center ticket on your behalf regarding your question: How to hot-track GridView cells?. Please bear with us, we will answer it shortly.
Hi,
The solution works great however, how do I clear the selection/Hottrack when the cursor is not over any row? For example if the users moves focus of the cursor away from the gridcontrol.
Hello,
I have created a ticket on your behalf regarding your question: How to implement the hot-track functionality for grid rows and remove hot tracking when the cursor is not over a row. Please refer to it.
Hello
thanks for this clue and code-example.
But I found a problem - if I add this "hot-tracking"-mode to a gridView, and use a RepositoryItemMemoExEdit with an info-symbol/image and this column as a dropDown (to show the text).I can not read the text, because after you click on the arrow button the popup appears only very briefly, and closes again automatically.
If I de-activate the "hot-tracking" the RepositoryItemMemoExEdit work fine…
Thanks & best regards
Michael
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
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.