Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listview and tooltips help please

Status
Not open for further replies.

Jesus4u

Programmer
Feb 15, 2001
110
US
I need to display a tooltip like message on a mouse over event in a listview to display the contents when the text is cut off by a column.

I have this code but it breaks in the code .SelectedItem.ListSubItems(LViewIndex). Message says index is out of bounds.

Any ideas?

Code:
Option Explicit

    Private Declare Function SendMessage Lib "user32" Alias _
        "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
        ByVal wParam As Long, lParam As Any) As Long
    
    Private Const LB_ITEMFROMPOINT = &H1A9

Code:
Private Sub lvwResults_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim ListXPos  As Long
    Dim ListYPos  As Long
    Dim LViewIndex As Long

    If Button = 0 Then ' if no button was pressed
       ListXPos = CLng(x / Screen.TwipsPerPixelX)
       ListYPos = CLng(y / Screen.TwipsPerPixelY)
    
       With lvwResults
          ' get selected item from list
          LViewIndex = SendMessage(.hwnd, LB_ITEMFROMPOINT, 0, _
               ByVal ((ListYPos * 65536) + ListXPos))
    
          ' show tip or clear last one
          If (LViewIndex >= 0) And (LViewIndex <= .ListItems.Count) Then
             .ToolTipText = .SelectedItem.ListSubItems(LViewIndex)
          Else
             .ToolTipText = &quot;&quot;
          End If
       End With
    End If


End Sub
 
listviews start at 1 not 0.
change your loops to start at 1 instead of 0

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top