devxlogo

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

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Seven Service Boundary Mistakes That Create Technical Debt

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.