Displaying a list where the line height would exactly fit the content is a very common need. 4D View Pro is including a new feature so that you can now control the height of each row independently in a listbox to make it fit to its content. To know more about 4D View Pro, check out this blog post.
There are actually now two ways to define the row height in a listbox:
- using new dedicated commands
- using a new control array
Using new commands
The new commands LISTBOX SET ROW HEIGHT and LISTBOX Get row height allow to set and get the height of each row individually.
If you execute this code:
LISTBOX SET ROW HEIGHT(*;"listboxname";1;184) //Pellentesque
LISTBOX SET ROW HEIGHT(*;"listboxname";2;41) //Vestibulumn
LISTBOX SET ROW HEIGHT(*;"listboxname";3;86) //Suspendisse
You get the following result:
Using a height control array
You can use this property to specify the name of the row height array you want to associate with the listbox.
For example, if you write:
//current unit is lines
ARRAY LONGINT(<>RowHeightArray;20)
<>RowHeightArray{5}:=3
The fifth row of the listbox will have a height of three lines, while every other row will keep their default height.
You can also associate the height control array by programming. The LISTBOX SET ARRAY and LISTBOX Get array commands now accept a Listbox row height array selector allowing you to define the row height control array via programming.
LISTBOX SET ARRAY ( {* ;} object ; Listbox row height array ; <>RowHeightArray )
<>RowHeightArray:=LISTBOX Get array ( {* ;} object ; Listbox row height array )
You want to try it by yourself ? Just download the following example!
For more details, please refer to the following articles in the 4D v16 documentation: