KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Setting Scroll Position to bottom of the Listbox
PRODUCT: 4D | VERSION: 13.3 | PLATFORM: Mac & Win
Published On: December 10, 2013

To set scroll of listbox to the bottom, use the command OBJECT SET SCROLL POSITION
The code below will set the listbox scroll position to a the selected position determined by the variable $row:

C_LONGINT($row)
$row:=5 //Row you want to scroll to

//ListBox is name of the ListBox object
OBJECT SET SCROLL POSITION(ListBox;$row)


To have to row selected to be on the top of the listbox, include the * parameter:

OBJECT SET SCROLL POSITION(ListBox;$row;*)


Using OBJECT SET SCROLL POSITION, we can scroll to selected row. Use LISTBOX GET CELL POSITION to determine the selected row:

C_LONGINT($col;$row)
C_POINTER($pos)
LISTBOX GET CELL POSITION(ListBox;$col;$row;$pos)
OBJECT SET SCROLL POSITION(ListBox;$row;*)


From the picture below, assume when you insert the name "Joe Smith" to the end of the listbox, you want to display the inserted row. Notice the scroll is at the top of the listbox.



You can use OBJECT SET SCROLL POSITION to move the scroll to the bottom, have the newly inserted row show up. To do this, use the following code:
//ListBox is name of the Listbox object
OBJECT SET SCROLL POSITION(ListBox;Size of array(ListBox)+1)


As a result, the scroll will be set to the bottom of the listbox, showing the newly inserted row.

See Also: