devxlogo

ListBoxEnsureVisible – Ensure that a ListBox element is visible

ListBoxEnsureVisible – Ensure that a ListBox element is visible

' ensure that a listbox item is visible' if the second argument is omitted, the index of current item is used'' NOTE: uses the ListBoxVisibleItems functionSub ListBoxEnsureVisible(lst As ListBox, Optional ByVal itemIndex As Long = -1)    Dim visibleCount As Long        ' provide a default for the 2nd argument    If itemIndex ' get the number of visible items    visibleCount = ListBoxVisibleItems(lst)        If itemIndex ' scroll up        lst.TopIndex = itemIndex    ElseIf itemIndex >= lst.TopIndex + visibleCount Then        ' scroll down        lst.TopIndex = itemIndex - visibleCount + 1    End If    End Sub

devx-admin

Share the Post: