|
-
Nov 7th, 2009, 08:05 PM
#1
[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
-
Nov 7th, 2009, 08:39 PM
#2
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.
-
Nov 7th, 2009, 08:43 PM
#3
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.
-
Nov 7th, 2009, 10:54 PM
#4
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
-
Nov 8th, 2009, 09:14 AM
#5
Re: listbox topindex change
 Originally Posted by westconn1
i did think about using the timer, just reduce its interval to a more responsive value
1 = 1/1000 of a second so I think it's fast enough.
-
Nov 8th, 2009, 03:14 PM
#6
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
-
Nov 8th, 2009, 03:30 PM
#7
Re: [RESOLVED] listbox topindex change
You can use multiple timers without any problem.
-
Nov 8th, 2009, 03:34 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|