flexgrid scroll problem

smilemax
01-29-2002, 09:26 AM
How can i differentiate between a
scroll left event , a scroll right event and a scroll up and down in a scrollbar of a flexgrid

Thanks
Smx

Flyguy
01-29-2002, 09:37 AM
You could check the:

MSFlexGrid1.TopRow
MSFlexGrid1.LeftCol

properties

smilemax
01-29-2002, 09:47 AM
Hi ArnoutV
I think I have not got your idea. Can i really trap the left or right scroll ? Can u explain me your reply.
Thanks
Smx

Volte
01-29-2002, 09:58 AM
Here is an example I made. This one actually uses subclassing to trap the events, and display them in the Immediate window. Becareful when you're running this. Always stop the program with the 'X' and not the 'End' statement or Stop button in the toolbar. This will cause the IDE to crash. Now, The Hand is the expert here, so he can say what isn't correct and such. This particular example will only do vertical scrollbar trapping, but using the API Viewer and some research, it's not that hard to trap the horizontal scrollbar.

In a modulePublic Const GWL_WNDPROC = (-4)
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public oldWindowProc As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_VSCROLL = &H115
Dim iPos As Long
Public Function NewWindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case uMsg
Case WM_VSCROLL
If wParam = 0 Or wParam = 2 Then
'scrolling up with the buttons or clicking on the track
Debug.Print "SCROLL: UP"
ElseIf wParam = 1 Or wParam = 3 Then
'scrolling down with the buttons or clicking on the track
Debug.Print "SCROLL: DOWN"
ElseIf wParam = 8 Then
'the mouse was just let up, do nothing
Else
'the slider is being dragged
If wParam = (iPos - 1) Then
'the mouse was just let up, do nothing
ElseIf wParam < iPos Then
'the slider is being dragged up
Debug.Print "SCROLL: UP"
Else
'the slider is being dragged down
Debug.Print "SCROLL: DOWN"
End If
'set the slider position variable
iPos = wParam
End If
End Select
NewWindowProc = CallWindowProc(oldWindowProc, hWnd, uMsg, wParam, lParam)
End Function


In a formPrivate Sub Form_Load()
'subclass the flexgrid
oldWindowProc = SetWindowLong(MSHFlexGrid1.hWnd, GWL_WNDPROC, AddressOf NewWindowProc)
End Sub

Private Sub Form_Unload(Cancel As Integer)
'unsubclass the flexgrid
SetWindowLong MSHFlexGrid1.hWnd, GWL_WNDPROC, oldWindowProc
End SubReplace the MSHFlexGrid1 in the form to whatever the name of your control is.

Flyguy
01-29-2002, 09:59 AM
This example is probably not 100% proof, but will do the trick:

Private Sub MSFlexGrid1_Scroll()
Static prevLeftCol As Long
Static prevTopRow As Long

With MSFlexGrid1
If prevLeftCol <> .LeftCol Then
MsgBox "scrolled left or right"
End If
If prevTopRow <> .TopRow Then
MsgBox "scrolled up or down"
End If
prevTopRow = .TopRow
prevLeftCol = .LeftCol
End With
End Sub

smilemax
01-29-2002, 10:09 AM
hi ArnoutV
Your code can differentiate between a scroll vertical and horizontal
Also i need to know if it is specifically a right or a left scroll
Is it possible ?
Thanks anyway
Smx

Flyguy
01-29-2002, 10:12 AM
Compare the value for eg. TopRow.

If .TopRow > prevTopRow Then
MsgBox "ScrollDown"
Else
MsgBox "ScrollUp"
End If

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum