Quote:
>Hi all
>How do I get the last visible Item in a ListView???
Fussel,
You'll need to know the Topindex, the Height of the Listbox and
the Height of a given item. From there it is simple math and
scaling. However, I believe the only way to get at the height of
a Listbox listitem is to toss it a LB_GETITEMHEIGHT message .
Neila
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
'Determines the height of each entry in the list control in pixels.
Private Const LB_GETITEMHEIGHT = &H1A1
Private Sub cmdTest_Click()
MsgBox LB_LastVisibleItem(lstTest)
End Sub
Private Sub Form_Load()
Dim strData As String
Dim I As Long
strData = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
For I = 1 To 26
lstTest.AddItem "Item: " & Mid$(strData, I, 1)
Next
End Sub
Private Function LB_LastVisibleItem(LB As ListBox) As Long
With LB
LB_LastVisibleItem = .TopIndex + (.Height / GetLBItemHeight(.hwnd) /
Screen.TwipsPerPixelY) - 1
End With
End Function
'Wrapper for the LB_GETITEMHEIGHT Listbox message
Private Function GetLBItemHeight(LBHwnd As Long) As Long
GetLBItemHeight = SendMessage(LBHwnd, LB_GETITEMHEIGHT, 0&, 0&)
End Function