alex_tr
5 years ago
Hi,

I'm trying to create a row hover effect.

I'm using the mouseEnter and mouseLeave events.

In mouseEnter, I change the CellBackColor for all the cells in the row.
In mouseLeave, I change the CellBackColor back to normal.

It's actually amazing how fast this works...

The only problem is a bit of flickering, as you might guess, when moving the mouse horizontally over the cells within the same row.

I made another version without using MouseLeave: in MouseEnter, if the row has changed I clear the old hover row and set the new one. This works fantastic (no flickering of course), but the row remains 'hovered' when the mouse moves outside the geography of the grid.

Is there a better way?

Alex
Igor/10Tec
5 years ago
First, show us your code. Perhaps, we can improve it to avoid flickering. In the ideal case, the row under the mouse pointer must be redrawn only one time, but it seems, this happens several times and causes flickering.
alex_tr
5 years ago
Hi

Thanks for offering to look at the code (and thanks for iGrid - it's life-changing! we just bought it.)

I have modified the approach since I posted this topic: I removed the MouseLeave event, and use the MouseMove events of both the iGrid obj and the parent form (I'm working in Access). The result is similar, but without the flickering when moving horizontally across cells in one row. I was afraid of performance issues with MouseMove, but it does not seem to slow it down too much.

I'm posting the code for this new approach anyway, in case you have any comments. If possible to improve it I will but otherwise I'm happy with this.

'
' Excerpts from class module used to manage iGrid
'
Option Compare Database
Option Explicit

Dim clrHover As Long = &HF5F5F5 'White Smoke
Dim lngCurrentHoverRow As Long
Dim clrNonHover As OLE_COLOR

Private Sub igObj_MouseEnter(ByVal lRow As Long, ByVal lCol As Long)
   Call hoverOn(lRow)
End Sub

Private Sub igObj_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single, ByVal lRowIfAny As Long, ByVal lColIfAny As Long)
   If (lRowIfAny = 0) Or (lColIfAny = 0) Then
      If lngCurrentHoverRow <> 0 Then
         Call hoverOff(lngCurrentHoverRow)
            lngCurrentHoverRow = 0
         End If
   End If
End Sub

Private Sub hoverOn(lRow As Long)
Dim i As Integer

   If lRow = lngCurrentHoverRow Then Exit Sub

   If lngCurrentHoverRow <> 0 Then
      Call hoverOff(lngCurrentHoverRow)
   End If

   With igObj
      'save the current colour
      clrNonHover = .CellBackColor(lRow, 1)

      'set to hover colour
      For i = 1 To .ColCount
         .CellBackColor(lRow, i) = clrHover
      Next i
   End With
   lngCurrentHoverRow = lRow

End Sub

Private Sub hoverOff(lRow As Long)
Dim i As Integer

   With igObj
      For i = 1 To .ColCount
         .CellBackColor(lRow, i) = clrNonHover
      Next i
   End With

End Sub

Public Sub EndHover()
'
' Procedure called from MouseMove event of form containing the iGrid
'
   If lngCurrentHoverRow <> 0 Then
      hoverOff (lngCurrentHoverRow)
      lngCurrentHoverRow = 0
   End If
End Sub
Igor/10Tec
5 years ago
I would recommend that you use the BeginUpdate/EndUpdate methods to wrap your calls to the CellBackColor property in the hoverOn and hoverOff subs. If you do not do this, iGrid repaints the contents of the row every time when you change CellBackColor for one of its cells. This brings additional flickering.
alex_tr
5 years ago
That makes it better, thank you.

I have also now added some logic to make the hover color alpha-blend with the cell background color. It looks really nice.