Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > flexgrid scroll problem


Reply
 
Thread Tools Display Modes
  #1  
Old 01-29-2002, 08:26 AM
smilemax
Guest
 
Posts: n/a
Default 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
Reply With Quote
  #2  
Old 01-29-2002, 08:37 AM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 18,931
Default

You could check the:
Code:
MSFlexGrid1.TopRow
MSFlexGrid1.LeftCol
properties
Reply With Quote
  #3  
Old 01-29-2002, 08:47 AM
smilemax
Guest
 
Posts: n/a
Default

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
Reply With Quote
  #4  
Old 01-29-2002, 08:58 AM
Volte's Avatar
Volte Volte is offline
Ultimate Contributor

Retired Leader
* Guru *
 
Join Date: Aug 2001
Posts: 5,343
Default

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.
Reply With Quote
  #5  
Old 01-29-2002, 08:59 AM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 18,931
Default

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
Reply With Quote
  #6  
Old 01-29-2002, 09:09 AM
smilemax
Guest
 
Posts: n/a
Default

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
Reply With Quote
  #7  
Old 01-29-2002, 09:12 AM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 18,931
Default

Compare the value for eg. TopRow.
Code:
If .TopRow > prevTopRow Then
  MsgBox "ScrollDown"
Else
  MsgBox "ScrollUp"
End If
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->