Is there a way to cause a listview to scroll through API?
Printable View
Is there a way to cause a listview to scroll through API?
The easiest way is to use SendMessage. Use the hWnd property of the listview.
Code:Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const SB_BOTH = 3
Public Const SB_BOTTOM = 7
Public Const SB_CONST_ALPHA = &H00000001
Public Const SB_CTL = 2
Public Const SB_ENDSCROLL = 8
Public Const SB_GRAD_RECT = &H00000010
Public Const SB_GRAD_TRI = &H00000020
Public Const SB_HORZ = 0
Public Const SB_ISSIMPLE = (WM_USER+14)
Public Const SB_LEFT = 6
Public Const SB_LINEDOWN = 1
Public Const SB_LINELEFT = 0
Public Const SB_LINERIGHT = 1
Public Const SB_LINEUP = 0
Public Const SB_NONE = &H00000000
Public Const SB_PAGEDOWN = 3
Public Const SB_PAGELEFT = 2
Public Const SB_THUMBPOSITION = 4
Public Const SB_THUMBTRACK = 5
Public Const WM_VSCROLL = &H2E
Dim wparam as long
wparam = SB_LINEDOWN
' scroll odwn one line
Call SendMessage Listview1.hWnd,WM_VSCROLL,SB_LINEDOWN,
_lparam, 0&
' scroll down one page
wparam = SB_PAGEDOWN
Call SendMessage Listview1.hWnd,WM_VSCROLL,SB_LINEDOWN,
_lparam, 0&
I can't figure out how to get this to work. :(
Make the following changes. I havent tested it, though, but I think it should fix the problem.
- Declare everything private, and put it in a Form.
- Erase the second SendMessage declaration.
- Remove "Call" from the line where SendMessage is called.
- Put from "Dim wparam as long" and onwards into a command button.
- Remove SB_LINEDOWN from the line where sendmessage is called, and replace it with wParam.
- Pick a function to use (either scrolling up or down). Keep those lines in your command button's procedure, and erase the rest
It was a little more complicated to fix than that, but I have it now. Thanks.