is it possible to detect when the topindex of a listbox changes, by mousewheel or any other method?
thnx
Printable View
is it possible to detect when the topindex of a listbox changes, by mousewheel or any other method?
thnx
Timer may come handy here:
NOTE: above sample is far from being complete so try enhancing it.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
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.
@ 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
my existing timer was working at 10000, too slow for thisQuote:
1 = 1/1000 of a second so I think it's fast enough.
You can use multiple timers without any problem.
i had no problem using one, just put a counter for the other line that only needed to fire every few seconds