Tracking the mouse in a list box

Posted on 2004-10-27
Medium Priority
Last Modified: 2010-05-02
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 !
Question by:levinlll
  • 2
LVL 86

Accepted Solution

Mike Tomlinson earned 500 total points
ID: 12426997
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
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
    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
LVL 77

Expert Comment

ID: 12427006
ListBox1.Tooltip = "My tooltip"
This seems too simple, so I may have misunderstood
LVL 77

Expert Comment

ID: 12427026
Yes. It was too simple. I had misunderstood.

Expert Comment

by:Ashutosh Vyas
ID: 12430432
Private Sub List1_MouseMove()
          List1.ToolTip = "ToolTip Text here"
End Sub

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question