Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
alex_tr  
#1 Posted : Saturday, November 23, 2019 12:54:13 PM(UTC)
alex_tr

Rank: Newbie

Groups: Registered
Joined: 10/30/2019(UTC)
Posts: 5

Thanks: 1 times
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  
#2 Posted : Tuesday, November 26, 2019 9:16:18 AM(UTC)
Igor/10Tec

Rank: Administration

Groups: Administrators, Forum Moderator
Joined: 1/17/2011(UTC)
Posts: 1,101

Thanks: 15 times
Was thanked: 141 time(s) in 141 post(s)
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  
#3 Posted : Tuesday, November 26, 2019 10:45:29 AM(UTC)
alex_tr

Rank: Newbie

Groups: Registered
Joined: 10/30/2019(UTC)
Posts: 5

Thanks: 1 times
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.

Code:

'
' 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

Edited by moderator Tuesday, November 26, 2019 2:19:05 PM(UTC)  | Reason: Igor/10Tec set language for code formatting

Igor/10Tec  
#4 Posted : Tuesday, November 26, 2019 2:21:54 PM(UTC)
Igor/10Tec

Rank: Administration

Groups: Administrators, Forum Moderator
Joined: 1/17/2011(UTC)
Posts: 1,101

Thanks: 15 times
Was thanked: 141 time(s) in 141 post(s)
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.
thanks 1 user thanked Igor/10Tec for this useful post.
alex_tr on 11/30/2019(UTC)
alex_tr  
#5 Posted : Saturday, November 30, 2019 10:13:31 AM(UTC)
alex_tr

Rank: Newbie

Groups: Registered
Joined: 10/30/2019(UTC)
Posts: 5

Thanks: 1 times
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.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.