Bring ListBox selection into view

  1. 2 months ago

    David C

    Aug 19 Boston, MA

    if an item in a listbox is being selected via selected(n) and it is out of view or beyond the scroll area, how can i
    bring that item in the list into view ie ( auto scroll to that item and selected it )

    Ex: listBox.Selected(n) = TRUE

    ListBox.ScrollPosition
    Property (As Integer)
    aListBox.ScrollPosition = newIntegerValue
    or
    IntegerValue = aListBox.ScrollPosition
    Zero-based index of the top visible row in the ListBox.

    Read ScrollPosition to determine the top visible row; write to ScrollPosition to scroll the ListBox. When the scrollbar thumb is scrolled to the bottom, ScrollPosition cannot be incremented any further.

  2. Dave S

    Aug 19 Answer San Diego, California USA

    ListBox.ScrollPosition
    Property (As Integer)
    aListBox.ScrollPosition = newIntegerValue
    or
    IntegerValue = aListBox.ScrollPosition
    Zero-based index of the top visible row in the ListBox.

    Read ScrollPosition to determine the top visible row; write to ScrollPosition to scroll the ListBox. When the scrollbar thumb is scrolled to the bottom, ScrollPosition cannot be incremented any further.

  3. David C

    Aug 19 Boston, MA

    ok great thank you !!

  4. 2 weeks ago

    Anthony M

    Oct 11 Pre-Release Testers, Xojo Pro
    Edited 2 weeks ago by Anthony M

    I have a similar problem. How would one do this if the selected item hasn't changed but the list order has, i.e. when sorted? For example, I have a listbox with 100 items and I click the header to sort the listbox the selected item may no longer be visible. How can I find the selected item and then scroll to that position?

  5. Emile S

    Oct 11 Europe (France, Strasbourg)

    Get the Selected Row number, then follow Dave's advice.

    @Anthony M How can I find the selected item

    In the Listbox Class reference, you will found an example to search all Selected Rows (one in your case).

or Sign Up to reply!