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?
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 = ""
End If
End With
End If
End Sub