Results 1 to 8 of 8

Thread: [RESOLVED] listbox topindex change

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Resolved [RESOLVED] listbox topindex change

    is it possible to detect when the topindex of a listbox changes, by mousewheel or any other method?

    thnx
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: listbox topindex change

    Timer may come handy here:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
    Dim i As Integer
    
        For i = 1 To 25
            List1.AddItem "Item " & i
        Next i
        
        Timer1.Interval = 1
        Timer1.Enabled = True
    
    End Sub
    
    Private Sub Timer1_Timer()
    Static lastIndex As Integer
    
        If lastIndex <> List1.TopIndex Then
            Debug.Print List1.List(List1.TopIndex)
        End If
        
        lastIndex = List1.TopIndex
    
    End Sub
    NOTE: above sample is far from being complete so try enhancing it.

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: listbox topindex change

    I struggled with that when I creatd my own unicode listbox in order to raise an event. I eventually gave in and cached the top index and then compared its value to the value returned by SendMessage [LB_GETTOPINDEX] during these subclassed messages:

    -- WM_MOUSEMOVE when button is down (i.e., dragging listbox item up/down to force scroll)
    -- WM_VSCROLL/WM_HSCROLL
    -- WM_COMMAND & lParam is lstbox hWnd & HiWord(wParam) is LBN_SELCHANGE
    -- Though I didn't use MW_MOUSEWHEEL, I would think it could be used also?

    If the listbox is ownerdrawn, you might want to get the top index during WM_DrawItem.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: listbox topindex change

    @ rhino i did think about using the timer, just reduce its interval to a more responsive value, but was looking if there were any alternatives

    @ lavolpe i found an example to use ownerdraw in vb.net to do this, but am not sure about modifying to vb6
    http://social.msdn.microsoft.com/for...d-0a8ef2a62886
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: listbox topindex change

    1 = 1/1000 of a second so I think it's fast enough.
    my existing timer was working at 10000, too slow for this
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [RESOLVED] listbox topindex change

    i had no problem using one, just put a counter for the other line that only needed to fire every few seconds
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

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