4D v13.4

Pop-up Menus/Drop-down Lists

Home

 
4D v13.4
Pop-up Menus/Drop-down Lists

Pop-up Menus/Drop-down Lists  


 

Use  

Pop-up menus and drop-down lists are objects that allow the user to select from a list. You manage the items displayed in the pop-up menu using an array. 

An array is a list of values in memory that is referenced by the name of the array (see the section Arrays and Form Objects). A pop-up menu/drop-down list displays an array as a list of values when you click on it. 

The names “Pop-up menu” and “Drop-down list” refer to the same objects; “Pop-up menu” is part of Mac OS terminology and “Drop-down list” is part of Windows.

As the following example shows, the appearance of these objects differs slightly according to the platform: 

Windows
Mac OS

You initialize the object 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. To do this, click on the Edit... button in the “Data Source” theme of the Property List. For more information, see Default lists of values. 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. A complete Case statement in the object method 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

In the Events section of the Property List window, you would 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.

For information about creating and using an array, refer to the Arrays chapter in the 4D Language Reference manual.

You can assign the Goto Page standard action to a pop-up menu/drop-down list (“Action” theme of the Property List). When this action is selected, 4D will automatically display the page of the form that corresponds to the number of the object that is selected in the drop-down list. 

For example, if the user selects the third item of the list, 4D will display the third page of the current form (if it exists).
If you want to manage the effect of the selection of an item yourself, select No action.

 
PROPERTIES 

Product: 4D
Theme: Working with active objects