Tracking the mouse in a list box

I'd like to be able to set the tooltip of a list box based on the entry the mouse is over a list box. Can anyone tell me how this can be accomplished ?

Thanks !
levinlllAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    (ByVal hWnd As Long, ByVal wMsg As Long, _
    ByVal wParam As Long, lParam As Long) As Long

Private Sub Form_Load()
    Dim i As Integer
   
    For i = 1 To 10
        List1.AddItem "Item " & i
    Next
End Sub

Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim idx As Integer
    idx = ListRowCalc(List1, Y)
    List1.ToolTipText = List1.List(idx)
End Sub
   
Private Function ListRowCalc(lstTemp As Control, ByVal Y As Single) As Integer
    Const LB_GETITEMHEIGHT = &H1A1
   
    Dim ItemHeight As Integer
    ItemHeight = SendMessage(lstTemp.hWnd, LB_GETITEMHEIGHT, 0, 0)
    ListRowCalc = min(((Y / Screen.TwipsPerPixelY) \ ItemHeight) + _
        lstTemp.TopIndex, lstTemp.ListCount - 1)
End Function

Private Function min(X As Integer, Y As Integer) As Integer
    If X > Y Then min = Y Else min = X
End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GrahamSkanRetiredCommented:
ListBox1.Tooltip = "My tooltip"
This seems too simple, so I may have misunderstood
0
GrahamSkanRetiredCommented:
Yes. It was too simple. I had misunderstood.
0
Ashutosh VyasFounder, InitQubeCommented:
Private Sub List1_MouseMove()
          List1.ToolTip = "ToolTip Text here"
End Sub
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.