4D v13.4Managing List Box Objects |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v13.4
Managing List Box Objects
Managing List Box Objects
The commands of this theme are dedicated to handling form objects of the List box type. List boxes represent data in the form of columns and selectable rows and provide many interface functions such as the ability to enter values, sort columns, display a hierarchy, define alternating colors, and so on. You can set up a List box completely in the 4D Form editor and can also manage it through programming. For more information on creating and setting List boxes in the Form editor as well as on their use, refer to the Design Reference manual of the 4D documentation. Programming List box objects is done in the same way as other 4D list form objects. However, specific rules must be followed, as detailed in this section. A list box can contain one or more columns and can be associated either with 4D arrays or a selection of records. In the case of selection type list boxes, columns are associated with fields or expressions. It is not possible to have both types of data sources (arrays and selections) combined in the same list box. The data source is set when the list box is created in the Form editor, via the Property list. It is then no longer possible to modify it by programming. In this type of list box, each column must be associated with a one-dimensional 4D array; all array types can be used, with the exception of pointer arrays. The display format for each column can be defined in the Form editor or by using the OBJECT SET FORMAT command. Using the language, the values of columns (data entry and display) are managed using high-level List box commands (such as LISTBOX INSERT ROWS or LISTBOX DELETE ROWS) as well as array manipulation commands. ARRAY TEXT(ColumnName;size) You can also use a list: LIST TO ARRAY("ListName";ColumnName) Warning : When a list box contains several columns of different sizes, only the number of items of the smallest array (column) will be displayed. You should make sure that each array has the same number of elements as the others. Also, if a list box column is empty (this occurs when the associated array was not correctly declared or sized using the language), the list box displays nothing. In this type of list box, each column can be associated with a field or an expression. The contents of each row is then evaluated according to a selection of records: the current selection of a table or a named selection. A List box object is composed of four separate items:
These items can be selected individually in the Form editor. Each one has its own object and variable name and can be handled separately. By default, columns are named Column1 to n, headers Header1 to n and footers Footer1 to n in the form, independently of the list box objects. Note that, by default, the same name is used for the objects and their associated variables, except in the case of footers (by default, footer variables are blank; 4D uses dynamic variables). Each item type contains individual and shared characteristics with other items. For example, character fonts can be globally assigned to the list box object or separately to columns, headers and/or footers. On the other hand, entry properties can only be defined for columns. These rules apply to the “Object properties” theme commands that can be used with list boxes. Depending on its functionality, each command can be used with the list box, columns, column headers and/or footers. To set the type of item on which you want to work, simply pass the object name or the variable associated with it. The following table details the scope of each command of the “Object properties” theme that can be used with list boxes:
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 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. 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:
(*) 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. (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) 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. 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 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. 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. Selection type list box: Selections are managed by a set called "Highlight Set." This set is defined in the properties of the list box. It is automatically maintained by 4D: If the user selects one or more rows in the list box, the set is immediately updated. On the other hand, it is also possible to use the commands of the "Sets" theme in order to modify the selection of the list box via programming.The variable linked to the List box object is used to get, set or store selections of object rows. This variable corresponds to a Boolean array that is automatically created and maintained by 4D. The size of this array is determined by the size of the list box: it contains the same number of elements as the smallest array linked to the columns. Each element of this array contains True if the corresponding line is selected and False otherwise. 4D updates the contents of this array depending on user actions. Inversely, you can change the value of array elements to change the selection in the list box. On the other hand, you can neither insert nor delete rows in this array; you cannot retype rows either. 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) 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:
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 Begin SQL |
PROPERTIES
Product: 4D SEE ALSO
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||