Skip to main content
Version: 18

Drop-down List

Overview

Drop-down lists are objects that allow the user to select from a list. You manage the items displayed in the drop-down list using an array, a choice list, or a standard action.

On macOS, drop-down lists are also sometimes called "pop-up menu". Both names refer to the same objects. As the following example shows, the appearance of these objects can differ slightly according to the platform:

Using an array

An array is a list of values in memory that is referenced by the name of the array. A drop-down list displays an array as a list of values when you click on it.

Drop-down list objects are initialized by loading a list of values into an array. You can do this in several ways:

  • Enter a list of default values in the object properties by selecting "\<Static List>" in the Data Source theme of the Property List. The default values are loaded into an array automatically. You can refer to the array using the name of the variable associated with the object.

  • Before the object is displayed, execute code that assigns values to the array elements. For example:

  ARRAY TEXT($aCities;6)
$aCities{1}:="Philadelphia"
$aCities{2}:="Pittsburg"
$aCities{3}:="Grand Blanc"
$aCities{4}:="Bad Axe"
$aCities{5}:="Frostbite Falls"
$aCities{6}:="Green Bay"

In this case, the name of the variable associated with the object in the form must be $aCities. This code could be placed in the form method and be executed when the On Load form event runs.

  • Before the object is displayed, load the values of a list into the array using the LIST TO ARRAY command. For example:
   LIST TO ARRAY("Cities";$aCities)

In this case also, the name of the variable associated with the object in the form must be $aCities. This code would be run in place of the assignment statements shown above.

If you need to save the user’s choice into a field, you would use an assignment statement that runs after the record is accepted. The code might look like this:

  Case of
:(Form event=On Load)
LIST TO ARRAY("Cities";aCities)
If(Record number([People])<0) `new record
aCities:=3 `display a default value
Else `existing record, display stored value
aCities:=Find in array(aCities;City)
End if
:(Form event=On Clicked) `user modified selection
City:=aCities{aCities} `field gets new value
:(Form event=On Validate)
City:=aCities{aCities}
:(Form event=On Unload)
CLEAR VARIABLE(aCities)
End case

You must select each [event] that you test for in your Case statement. Arrays always contain a finite number of items. The list of items is dynamic and can be changed by a method. Items in an array can be modified, sorted, and added to.

Using a choice list

If you want to use a drop-down list to manage the values of a listed field or variable, 4D lets you reference the field or variable directly as the object's data source. This makes it easier to manage listed fields/variables.

If you use a hierarchical list, only the first level is displayed and can be selected.

For example, in the case of a "Color" field that can only contain the values "White", "Blue", "Green" or "Red", it is now possible to create a list containing these values and associate it with a pop-up menu object that references the 4D "Color" field. 4D then automatically takes care of managing the input and display of the current value in the form.

To associate a pop-up menu/drop-down list or a combo box with a field or variable, you can just enter the name of the field or variable directly in the Variable or Expression of the object in the Property List.

When the form is executed, 4D automatically manages the pop-up menu or combo box during input or display: when a user chooses a value, it is saved in the field; this field value is shown in the pop-up menu when the form is displayed:

It is not possible to combine this principle with using an array to initialize the object. If you enter a field name in the Variable Name area, then you must use a choice list.

Save as

When you have associated a pop-up menu/drop-down list with a choice list and with a field, you can use the Save as Value/Reference property. This option lets you optimize the size of the data saved.

Using a standard action

You can assign a standard action to a pop-up menu/drop-down list (Action theme of the Property List). Only actions that display a sublist of items (except the goto page action) are supported by this object. For example, if you select the backgroundColor standard action, at runtime the object will display an automatic list of background colors. You can can override this automatic list by assigning in addition a choice list in which each item has been assigned a custom standard action.

For more information, please refer to the Standard actions section.

Supported Properties

Alpha Format - Bold - Bottom - Button Style - Choice List - Class - Date Format - Expression Type - Focusable - Font - Font Color - Font Size - Height - Help Tip - Horizontal Sizing - Italic - Left - Not rendered - Object Name - Right - Standard action - Save as - Time Format - Top - Type - Underline - Variable or Expression - Vertical Sizing - Visibility - Width