 |
 |

01-29-2002, 08:26 AM
|
|
|
flexgrid scroll problem
|
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
|
|

01-29-2002, 08:37 AM
|
 |
Lost Soul
Super Moderator * Guru *
|
|
Join Date: May 2001
Location: Vorlon
Posts: 18,931
|
|
You could check the:
Code:
MSFlexGrid1.TopRow
MSFlexGrid1.LeftCol
properties
|
|

01-29-2002, 08: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
|
|

01-29-2002, 08:58 AM
|
 |
Ultimate Contributor
Retired Leader * Guru *
|
|
Join Date: Aug 2001
Posts: 5,343
|
|
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 module
Code:
Public 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 form
Code:
Private 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 Sub
Replace the MSHFlexGrid1 in the form to whatever the name of your control is.
|
|

01-29-2002, 08:59 AM
|
 |
Lost Soul
Super Moderator * Guru *
|
|
Join Date: May 2001
Location: Vorlon
Posts: 18,931
|
|
This example is probably not 100% proof, but will do the trick:
Code:
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
|
|

01-29-2002, 09: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
|
|

01-29-2002, 09:12 AM
|
 |
Lost Soul
Super Moderator * Guru *
|
|
Join Date: May 2001
Location: Vorlon
Posts: 18,931
|
|
Compare the value for eg. TopRow.
Code:
If .TopRow > prevTopRow Then
MsgBox "ScrollDown"
Else
MsgBox "ScrollUp"
End If
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|