Results 1 to 7 of 7

Thread: how can you scroll a listbox?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    83
    i can't figure out how to scroll a listbox(IN CODE!), hopefully there is a better way to than to setfocus on the last item
    Ian Callanan
    VB6.0
    [email protected]

  2. #2
    Guest
    Well, there is a pretty stupid way i know. you can just send the {DOWN} key to your App.

    But i'm sure there's a better way that that.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    83
    thanks, but i finally thought of a way(sadly kinda what i implied)

    list1.ListIndex = list1.ListCount - 1
    list1.ListIndex = -1

    this moves it to the bottom yet doesn't highlight visiblely

    thanks for trying, i just figured there was another, better way

    oh, and i didn't know about the list1.listcount command
    Ian Callanan
    VB6.0
    [email protected]

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    You could use the SendMessage API with the WM_VSCROLL Message, i.e.
    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Private Const WM_VSCROLL = &H115
    Private Const SB_LINEDOWN = 1
    Private Const SB_LINEUP = 0
    Private Const SB_PAGEDOWN = 3
    Private Const SB_PAGEUP = 2
    Private Const SB_TOP = 6
    Private Const SB_BOTTOM = 7
    
    Private Sub Command1_Click()
        SendMessage List1.hwnd, WM_VSCROLL, SB_BOTTOM, ByVal 0&
    End Sub

  5. #5
    Guest
    I usually use:

    Code:
    On Error Resume Next 'stops the error for when the listindex reaches the very bottom of the list
    List1.listindex = List1.listindex + 1
    That's all.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    83
    again thanks to everyone, but i am content with my code, short and very effective it seems to find the very bottom

    (read above to see code)
    Ian Callanan
    VB6.0
    [email protected]

  7. #7
    Junior Member
    Join Date
    May 2000
    Posts
    25

    Lightbulb

    I know I'm kinda late, but...

    the TopIndex property is specifically meant for scrolling through a listbox in code.(The help file mentions that when it describes the function)

    That way you don't have to do a work-around.

    Hope that helped.

    ______

    Bob K.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width