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 < 0 Then itemIndex = lst.ListIndex        ' get the number of visible items    visibleCount = ListBoxVisibleItems(lst)        If itemIndex < lst.TopIndex Then        ' scroll up        lst.TopIndex = itemIndex    ElseIf itemIndex >= lst.TopIndex + visibleCount Then        ' scroll down        lst.TopIndex = itemIndex - visibleCount + 1    End If    End Sub

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist