[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 76

Expert Comment

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 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