Last Visible Item 
Author Message
 Last Visible Item

Hi all

How do I get the last visible Item in a ListView???

Sat, 08 Dec 2001 03:00:00 GMT  
 Last Visible Item


>Hi all

>How do I get the last visible Item in a ListView???

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 .

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
    For I = 1 To 26
        lstTest.AddItem "Item: " & Mid$(strData, I, 1)
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

Sat, 08 Dec 2001 03:00:00 GMT  
 [ 2 post ] 

 Relevant Pages 

1. Listview : make last added item visible everytime ?

2. ItemRemove event don't fire when removing last item in items collection object

3. All items in my collection = the last item added

4. Get last visible line of RichTextBox

5. ListView: How to make the last column visible.

6. First Visible item in Treeview

7. Making pivot table "(blank)" items visible

8. Combobox with items visible

9. Which items of listview are visible?

10. Items In Detail Mode Not Visible..

11. Datacombo: setting the number of visible items without scrolling

12. Number of visible items in listbox control


Powered by phpBB® Forum Software