Tech Tip: Setting rows in a listbox to fit the height of the listbox
PRODUCT: 4D | VERSION: 15.1 | PLATFORM: Mac & Win
Published On: February 3, 2016
Below is an utility method to fit rows in a listbox to the height of the listbox. The method takes in an optional 2nd parameter to specify the number of rows to show.
// Method name: LB_SET_ROWS_HEIGHT // Sets the height of the rows so they fit the listbox // $1 - pointer to the listbox // ($2) - number of rows to shown C_POINTER($1;$LB) C_LONGINT($2;$numRows) C_LONGINT($rowPixels;$newPixel) C_LONGINT($left;$top;$right;$bot;$lbHeight) C_LONGINT($headerHeight;$scrollHeight;$footerHeight) If (Count parameters>=1) $LB:=$1 If (Count parameters>=2) $numRows:=$2 Else $numRows:=LISTBOX Get number of rows($LB->) End if $rowPixels:=LISTBOX Get rows height($LB->;Listbox pixels) OBJECT GET COORDINATES($LB->;$left;$top;$right;$bot) $lbHeight:=$bot-$top $headerHeight:=LISTBOX Get information($LB->;Listbox header height) $scrollHeight:=LISTBOX Get information($LB->;Listbox hor scrollbar height) $footerHeight:=LISTBOX Get information($LB->;Listbox footer height) $lbHeight:=$lbHeight-$headerHeight-$scrollHeight-$footerHeight $newPixel:=$lbHeight/$numrows LISTBOX SET ROWS HEIGHT($LB->;$newPixel) End if |
Example:
The listbox below contains a few pictures:
After running the following code:
LB_SET_ROWS(->ListBox) |
The rows are adjusted to fit into the listbox: