4D v14.3Managing List Box Objects |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v14.3
Managing List Box Objects
|
Object Properties commands | Object | Columns | Column headers | Column footers |
OBJECT MOVE | X | |||
OBJECT GET COORDINATES | X | |||
OBJECT SET RESIZING OPTIONS | X | |||
OBJECT GET RESIZING OPTIONS | X | |||
OBJECT SET FILTER | X | |||
OBJECT SET FORMAT | X | X | ||
OBJECT SET ENTERABLE | X | |||
OBJECT SET CHOICE LIST NAME | X | |||
OBJECT SET TITLE | X | |||
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 GET BEST SIZE | X | 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 (“Object Properties” 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 it is applied to a listbox in selection mode, the REDRAW command ("User Interface" theme) triggers the updating of the data displayed in the list box.
The Displayed line number command (“Selections” 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 command.
Managing the drag and drop of data in list boxes is supported by the Drop position and 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: Beginning with 4D v13, the On Before Data Entry event is returned before On Getting Focus.
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 forbid 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 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.
Selections are managed differently depending on whether the list box is based on an array or on a selection.
Note: The Count in array command can be used to find out the number of selected lines.
For example, this method allows inverting the selection of the first row of the (array type) list box:
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
Note: The specificities of managing selections in list boxes that are in hierarchical mode are detailed in the Managing Hierarchical List Boxes section.
It is possible to print list boxes beginning with 4D v12. 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 in directly printing the list box with 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. Accordingly, only list boxes found in project forms can be printed in advanced mode. 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 | |
low priority | List box properties |
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 for an object to inherit the attribute value from a higher level, you can use pass -255 (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:
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
Product: 4D
Theme: List Box
Managing Hierarchical List Boxes
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)
Inherited from : Managing List Box Objects ( 4D v13.5)