This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v20 R7
Managing List Box Objects
|
Object Properties commands | Object | Columns | Column headers | Column footers |
OBJECT MOVE | X | |||
OBJECT GET COORDINATES | X | X | X | X |
OBJECT SET RESIZING OPTIONS | X | |||
OBJECT GET RESIZING OPTIONS | X | |||
OBJECT GET BEST SIZE | X | |||
OBJECT SET FILTER | X | |||
OBJECT SET FORMAT | X | X | X | |
OBJECT SET ENTERABLE | X | |||
OBJECT SET LIST BY NAME | X | |||
OBJECT SET TITLE | X | |||
_o_OBJECT SET COLOR | X | X | X | X |
OBJECT SET RGB COLORS | X | X | X | X |
OBJECT SET FONT | X | X | X | X |
OBJECT SET FONT SIZE | X | X | X | X |
OBJECT SET FONT STYLE | X | X | X | X |
OBJECT SET HORIZONTAL ALIGNMENT | X | X | X | X |
OBJECT Get horizontal alignment | X | X | X | X |
OBJECT SET VERTICAL ALIGNMENT | X | X | X | X |
OBJECT Get vertical alignment | X | X | X | X |
OBJECT SET VISIBLE | X | X | X | X |
OBJECT SET SCROLLBAR | X | |||
OBJECT SET SCROLL POSITION | X | |||
OBJECT SET HELP TIP | X | X | X | |
OBJECT Get help tip | X | X | X |
Note: With array type list boxes, it is possible to specify the style, font color, background color and visibility of each row separately. This is managed via arrays associated with the list box in the Property List. You can retrieve the names of these arrays by programming using the LISTBOX GET ARRAYS command.
It is possible to add an object method to the list box object and/or to each column of the list box. Object methods are called in the following order:
1. Object method of each column
2. Object method of the list box
The column object method gets events that occur in its header and footer.
When the OBJECT SET VISIBLE command is used with a header or footer, it is used on all List box object headers or footers, regardless of the individual element set by the command. For example, the OBJECT SET VISIBLE(*;"header3";False) instruction will hide all headers in the List box object to which header3 belongs and not simply this header.
Note that in order for you to be able to manage the visibility of these objects using the OBJECT SET VISIBLE command, they must have been displayed in the list box at the level of the Form editor (the Display Headers and/or Display Footers option must be checked for the object).
The OBJECT Get pointer function used with the Object with focus or Object current constant (formerly the Focus object and Self functions) can be used in the object method of a list box or a list box column. They return a pointer to the list box, the list box column(1) or the header variable depending on the type of form event. The following table details this functioning:
Event | Object with focus | Object current |
On Clicked | list box | column |
On Double Clicked | list box | column |
On Before Keystroke | column | column |
On After Keystroke | column | column |
On After Edit | column | column |
On Getting Focus | column or list box (*) | column or list box (*) |
On Losing Focus | column or list box (*) | column or list box (*) |
On Drop | list box source | list box (*) |
On Drag Over | list box source | list box (*) |
On Begin Drag Over | list box | list box (*) |
On Mouse Enter | list box (**) | list box (**) |
On Mouse Move | list box (**) | list box (**) |
On Mouse Leave | list box (**) | list box (**) |
On Data Change | column | column |
On Selection Change | list box (**) | list box (**) |
On Before Data Entry | column | column |
On Column Moved | list box | column |
On Row Moved | list box | list box |
On Column Resize | list box | column |
On Open Detail | Nil | list box (**) |
On Close Detail | Nil | list box (**) |
On Header Click | list box | header |
On Footer Click | list box | footer |
On After Sort | list box | header |
(*) When the focus is modified within a list box, a pointer to the column is returned. When the focus is modified at the overall form level, a pointer to the list box is returned. In the context of a column object method, a pointer to the column is returned.
(**) Not executed in the context of a column object method.
(1) When a pointer to a column is returned, the object pointed to depends on the type of list box. With an array type list box, the OBJECT Get pointer function (“User Interface” theme) returns a pointer to the column of the list box with the focus (i.e. to an array). The 4D pointer mechanism allows you to see the item number of the modified array. For example, supposing a user modified the 5th line of the column col2:
$Column:=OBJECT Get pointer(Object with focus)
` $Column contains a pointer to col2
$Row:=$Column-> `$Row equals 5
For a selection type list box, the OBJECT Get pointer function returns:
The OBJECT SET SCROLL POSITION command (“Objects (Forms)” theme) can be used with a list box. It scrolls the list box rows so that the first selected row or a specified row is displayed.
The EDIT ITEM command (“Entry Control” theme) allows you to pass a cell of a list box object into edit mode.
When applied to a listbox in selection mode, the REDRAW command ("User Interface" theme) triggers an update of the data displayed in the list box.
Note: The REDRAW command is not supported with list box of the entity selection type.
The Displayed line number command (“Selection” theme) functions in the context of the On Display Detail form event for a list box object.
Specific form events are intended to facilitate list box management, in particular concerning drag and drop and sort operations. For more information, refer to the description of the Form event code command.
Managing the drag and drop of data in list boxes is supported by the Drop position and _o_DRAG AND DROP PROPERTIES commands. These commands have been specially adapted for list boxes.
Be careful not to confuse drag and drop with the moving of rows and columns, supported by the LISTBOX MOVED ROW NUMBER and LISTBOX MOVED COLUMN NUMBER commands.
For a list box cell to be enterable, both of the following conditions must be met:
Let’s consider the example of a list box containing two arrays, one date and one text. The date array is not enterable but the text array is enterable if the date has not already past.
Here is the method of the arrText column:
Case of
:(FORM Event=On Before Data Entry) // a cell gets the focus
LISTBOX GET CELL POSITION(*;"lb";$col;$row)
// identification of cell
If(arrDate{$row}<Current date) // if date is earlier than today
$0:=-1 // cell is NOT enterable
Else
// otherwise, cell is enterable
End if
End case
Note: Since 4D v13, the On Before Data Entry event is returned before On Getting Focus.
In order to preserve data consistency for selection type and entity selection type list boxes, any modified record/entity is automatically saved as soon as the cell is validated, i.e.:
The typical sequence of events generated during data entry or modification is as follows:
Action | Listbox type(s) | Sequence of events |
A cell switches to edit mode | All | On Before Data Entry |
All | On Getting Focus | |
Its value is modified | All | On Before Keystroke |
All | On After Keystroke | |
All | On After Edit | |
A user validates and leaves the cell | Selection list boxes | Save |
Record selection list boxes | On saving an existing record trigger (if set) | |
Selection list boxes | On Data Change(*) | |
Entity selection list boxes | Entity is saved with automerge option, optimistic lock (see entity.save( )). In case of successful save, the entity is refreshed with the last update done. If the save operation fails, an error is displayed | |
All | On Losing Focus |
(*) With entity selection list boxes, in the On Data Change event:
Note: Data entry in collection/entity selection type list boxes has a limitation when the expression evaluates to null. In this case, it is not possible to edit or remove the null value in the cell.
By default, the list box automatically handles standard column sorts when the header is clicked. A standard sort is an alphanumeric sort of column values, alternately ascending/descending with each successive click. All columns are always synchronized automatically.
You can prevent standard user sorts by deselecting the “Sortable” property of the list box.
The developer can set up custom sorts using the LISTBOX SORT COLUMNS command and/or combining the On Header Click and On After Sort form events (see the Form event code command) and array management 4D commands.
Note: The “Sortable” column property only affects the standard user sorts; the LISTBOX SORT COLUMNS command does not take this property into account.
The value of the variable related to the column header allows you to manage additional information: the current sort of the column (read) and the display of the sort arrow.
You can set the value of the variable (for example, Header2:=2) in order to “force” the sort arrow display. The column sort itself is not modified in this case; it is up to the developer to handle it.
Note: The OBJECT SET FORMAT command offers specific support for icons in list box headers, which can be useful when you want to work with a customized sort icon.
Selections are managed differently depending on whether the list box is based on an array, on a selection of records, or on a collection/entity selection:
ARRAY BOOLEAN(tBListBox;10)
//tBListBox is the name of the list box variable in the form
If(tBListBox{1}=True)
tBListBox{1}:=False
Else
tBListBox{1}:=True
End if
If you have checked the Hide selection highlight option for a list box, you will need to make list box selections visible using available interface options. For more information about how to do this, see Customizing the appearance of selections.
Note: The specifics for managing selections in list boxes in hierarchical mode are detailed in the Managing Hierarchical List Boxes section.
Two printing modes are available: preview mode - which can be used to print a list box like a form object, and advanced mode - which lets you control the printing of the list box object itself within the form. Note that the "Printing" appearance is available for list box objects in the Form editor.
Printing a list box in preview mode consists of directly printing the list box and the form that contains it using the standard print commands or the Print menu command. The list box is printed as it is in the form. This mode does not allow precise control of the printing of the object; in particular, it does not allow you to print all the rows of a list box that contains more rows than it can display.
In this mode, the printing of list boxes is carried out by programming, via the Print object command (project forms and table forms are supported). The LISTBOX GET PRINT INFORMATION command is used to control the printing of the object.
In this mode:
There are several different ways to set background colors, font colors and font styles for list boxes:
Priority and inheritance principles are observed.
When the same property is set at more than one level, the following priority is applied:
high priority | Cell (if multi-style text) |
Column arrays/methods | |
List box arrays/methods | |
Column properties | |
List box properties | |
low priority | Meta Info expression (for collection or entity selection list boxes) |
For example, if you set a font style in the list box properties and another using a style array for the column, the latter one will be taken into account.
Given a list box where the rows have an alternating gray/light gray color, defined in the properties of the list box. A background color array has also been set for the list box in order to switch the color of rows where at least one value is negative to light orange:
<>_BgndColors{$i}:=0x00FFD0B0 // orange
<>_BgndColors{$i}:=-255 // default value
Next you want to color the cells with negative values in dark orange. To do this, you set a background color array for each column, for example <>_BgndColor_1, <>_BgndColor_2 and <>_BgndColor_3. The values of these arrays have priority over the ones set in the list box properties as well as those of the general background color array:
<>_BgndColorsCol_3{2}:=0x00FF8000 // dark orange
<>_BgndColorsCol_2{5}:=0x00FF8000
<>_BgndColorsCol_1{9}:=0x00FF8000
<>_BgndColorsCol_1{16}:=0x00FF8000
You can get the same result using the LISTBOX SET ROW FONT STYLE and LISTBOX SET ROW COLOR commands. They have the advantage of letting you skip having to predefine style/color arrays for the columns: instead they are created dynamically by the commands.
For each attribute (style, color and background color), an inheritance is implemented when the default value is used:
This way, if you want an object to inherit the attribute value from a higher level, you can use pass the lk inherited constant (default value) to the definition command or directly in the element of the corresponding style/color array.
Given a list box containing a standard font style with alternating colors:
You perform the following modifications:
To restore the original appearance of the list box, you can:
You can set the "hidden", "disabled" and "selectable" interface properties for each row in an array-based list box.
These settings can be handled by the Row Control Array, which you can designate using the LISTBOX SET ARRAY command or through the Property list:
A row control array must be of the Longint type and include the same number of rows as the list box. For more information, refer to the List box specific properties section.
Each element of the Row Control Array array defines the interface status of its corresponding row in the list box. Three interface properties are available using constants in the "List Box" constant theme:
Constant | Type | Value | Comment |
lk row is disabled | Longint | 2 | The corresponding row is disabled. The text and controls such as check boxes are dimmed or grayed out. Enterable text input areas are no longer enterable. Default value: Enabled |
lk row is hidden | Longint | 1 | The corresponding row is hidden. Hiding rows only affects the display of the list box. The hidden rows are still present in the arrays and can be managed by programming. The language commands, more particularly LISTBOX Get number of rows or LISTBOX GET CELL POSITION, do not take the displayed/hidden status of rows into account. For example, in a list box with 10 rows where the first 9 rows are hidden, LISTBOX Get number of rows returns 10. From the user’s point of view, the presence of hidden rows in a list box is not visibly discernible. Only visible rows can be selected (for example using the Select All command). Default value: Visible |
lk row is not selectable | Longint | 4 | The corresponding row is not selectable (highlighting is not possible). Enterable text input areas are no longer enterable unless the "Single-Click Edit" option is enabled. Controls such as check boxes and lists are still functional however. This setting is ignored if the list box selection mode is "None". Default value: Selectable |
To change the status for a row, you just need to set the appropriate constant(s) to the corresponding array element. For example, if you do not want row #10 to be selectable, you can write:
aLControlArr{10}:=lk row is not selectable
You can define several interface properties at once:
aLControlArr{8}:=lk row is not selectable+lk row is disabled
Note that setting properties for an element overrides any other values for this element (if not reset). For example:
aLControlArr{6}:=lk row is disabled+lk row is not selectable //sets row 6 as disabled AND not selectable
aLControlArr{6}:=lk row is disabled //sets row 6 as disabled but selectable again
When the Hide selection highlight option is checked (see Appearance theme section), you need to make list box selections visible using available interface options. Since selections are still fully managed by 4D, this means:
You can then define specific background colors, font colors and/or font styles by programming to customize the appearance of selected rows. This can be done using arrays or expressions, depending on the type of list box being displayed (see the following sections).
Note: You can use the lk inherited constant to mimic the current appearance of the list box (e.g., font color, background color, font style, etc.). For more information about how the lk inherited constant works, refer to the Inheritance description.
To determine which rows are selected, you have to check whether they are included in the set indicated in the Highlight Set property of the list box:
You can then define the appearance of selected rows using one or more of the following expressions specified in the Property List:
Note: Keep in mind that expressions are automatically re-evaluated each time the:
Break rows cannot be highlighted when the Hide selection highlight option is checked.
Since it is not possible to have distinct colors for headers of the same level, there is no way to highlight a specific break row by programming.
You have to parse the Boolean array variable associated with the list box to determine whether rows are selected or not selected:
You can then define the appearance of selected rows using one or more of the following arrays specified in the Property List:
Note that list box arrays used for defining the appearance of selected rows must be recalculated during the On Selection Change form event; however, you can also modify these arrays based on the following additional form events:
...depending on whether and how you want to visually represent changes of focus in selections.
You have chosen to hide the system highlight and want to display list box selections with a green background color, as shown here:
For an array type list box, you need to update the Row Background Color Array by programming:
In the object method of the list box, you can write:
Case of
:(FORM Event=On Selection Change)
$n:=Size of array(LB_Arrays)
ARRAY LONGINT(_ListboxBackground;$n) // row background colors
For($i;1;$n)
If(LB_Arrays{$i}=True) // selected
_ListboxBackground{$i}:=0x0080C080 // green background
Else // not selected
_ListboxBackground{$i}:=lk inherited
End if
End for
End case
For a selection type list box, to produce the same effect you can use a method to update the Background Color Expression based on the set specified in the Highlight Set property. For example:
In the UI_SetColor method, you can write:
If(Is in set("$SampleSet"))
$color:=0x0080C080 // green background
Else
$color:=lk inherited
End if
$0:=$color
Warning: Do not forget to check the Hide selection highlight option to disable system highlight (see above).
It is possible to place the results of an SQL query directly in an array type list box. This offers a rapid means for viewing the results of SQL queries. Only queries of the SELECT type can be used. This mechanism cannot be used with an external SQL database.
It works according to the following principles:
Example
We want to retrieve all the fields of the PEOPLE table and put their contents into the list box having the variable name vlistbox. In the object method of a button (for example), simply write:
Begin SQL
SELECT * FROM PEOPLE INTO <<vlistbox>>
End SQL
Customize Highlight Color (4D blog)
Download HDI database
Tutoriaux sur les list box
Product: 4D
Theme: List Box
Modified: 4D v15 R4
Modified: 4D v16 R2
Modified: 4D v17
4D Language Reference ( 4D v20 R7)