Using Combo Boxes and List Boxes

In this section:

How to:

Reference:

Combo boxes and list boxes enable end users to select a value from a list. List boxes display as much of the list as there is room in the box. If the list is larger than the box, WebFOCUS Maintain will display scroll bars to enable end users to view the other options. You can also enable list boxes so that the end user can select more than one option. Combo boxes are only one line long. To select an option, the end user must click the arrow at the right side of the box to see the list.

The contents of the list are determined dynamically at run time by one of the following:


Top of page

x
Procedure: How to Place a Combo Box or a List Box on Your Form
  1. Select the Combo box control or the List box control in the Controls palette.
  2. Draw a rectangle on your form approximately where you want your combo box or list box to be at approximately the size you want.
  3. Giving your combo box or list box a more meaningful name than ComboBoxn or ListBoxn is optional, but recommended.
  4. If necessary, readjust the size and placement of your combo box or list box.
  5. Double-click the combo box or list box or select the ListItems property to open the List Source dialog box. Use this dialog box to determine the items in your list.
  6. You have four options for defining the items in your combo box or list box:
    • From the ACCEPT list of a data source field. Select From a variable and select the column in the list of variables. You will only see this option if any data source this procedure is using contains a field with an ACCEPT list.
  7. Click OK.
  8. Select the SelectedItem or SelectedItems property to open the Binding the Selection Result dialog box. Use this dialog box to bind the end users choice in the combo box or list box to a data source stack column or variable.

    Caution: Do not bind SelectedItem or SelectedItems to a data source stack that already contains data. This will replace the contents of the data source stack with the result of the selection.

    Note: Since end users can select multiple values in a list box, you must bind the value to a stack.

  9. Select a data source stack column or variable. You can create a data source stack or variable by clicking New data source stack or New variable. For more information, see How to Create a Data Source Stack Explicitly Using the Stack Editor or How to Create a Variable in a Procedure.
  10. Determine whether to store the text or the values you entered in the List Source dialog box.
  11. Click OK.
  12. If you are placing a list box on your form and you want your end users to be able to select more than one item, set the MultiSelection property to 1 - Yes.

Top of page

x
Procedure: How to Enter Items Manually in the List Source Dialog Box

To create an item in the List Source dialog box, do one of the following:

To edit an item in the List Source dialog box, do one of the following:

Tip: To define the list, you can drag text from any application (for example, Notepad) on top of a combo box, list box, or group of radio buttons.


Top of page

x
Syntax: How to Set the Value of a Combo Box or List Box Dynamically

If you want to set the value of a combo box or list box dynamically, issue the following command

COMPUTE Formname.ControlName.ListItems.FocIndex = n;

where:

Formname

Is the name of the form the check box is placed on.

ControlName

Is the name of the combo box or list box.

ListItems

Is the name of an internal data source stack that contains the values for the combo box or list box.

You can also reset the values of all controls in a form to their initial values using the Winform Reset command. For more information, see Manipulating Form Properties.


Top of page

x
Syntax: How to Preselect Items in a Multi-Select List Box by Value

You can preselect items in a list box with the MultiSelection property turned on using the following syntax:

Winform Show_Inactive Formname;Formname.ListBoxName.SelectedItems(1) = "value1";Formname.ListBoxName.SelectedItems(2) = "value2";
.
.
. 
Formname.ListBoxName.SelectedItems(m) = "valuen";

where:

Formname

Is the name of the form the check box is placed on.

ListBoxName

Is the name of the list box.

SelectedItems

Is the name of an internal data source stack that can contain an array of multiple preselected items. Like all stacks, it is a 1-based, not 0-based, array.


Top of page

x
Procedure: How to Trigger an Action When Selecting From a Combo Box or List Box
  1. Open the Event Handler editor.
  2. Select the combo box or list box in the list of controls.
  3. Select the Change event from the list of events.
  4. Specify an event handler.

Top of page

x
Reference: List Source Dialog Box

The List Source dialog box is used to determine the contents of your list box, radio button, or combo box.

List Source Dialog box

The List Source dialog box contains the following elements:

Insert list items

Select As entered here to manually enter list items.

Select From a variable to retrieve the list from a data source stack column, variable with data type Stack of, or ACCEPT list for a data source field. This enables you to determine at run time which items should appear in the list. When you select this option, you will see a list of available Maintain variables in your procedure and data source fields with ACCEPT lists.

Text

Displays the prompt text for each item.

Value

Displays the values assigned to the prompt text for each item.

Adds a selected item to the list of fields by opening the Enter a List Item dialog box.

Deletes a selected item from the list of items.

Moves a selected item up in the list of items.

Moves a selected item down in the list of items.

List Source Dialog box

New variable

Opens the New Variable dialog box, where you can create a variable with the data type, Stack of.

New data source stack

Opens the Stack Editor, where you can create a stack.

List of data source stacks and variables in your procedure

Contains a list of the existing stacks and variables in your procedure. Either select a variable, or expand a data source stack and select a column.

Data Sources - Fields with Accept List

Lists the data sources used in this procedure with fields that have an ACCEPT list. You will not see this option if you do not have any such fields.


Top of page

x
Reference: Enter a List Item Dialog Box

You can use the Enter a List Item dialog box to manually enter list items and assign values to the items you enter.

Enter a List Item Dialog Box

This dialog box contains the following elements:

Item text

Contains the list item displayed to the end user.

Assigned value (optional)

Contains the value generated if the end user selects this item. Later, you can store this value in the data source.


Top of page

x
Reference: Binding the Selection Result Dialog Box

Use the Binding the Selection Result dialog box to bind your selection results to a variable or data source stack column as text, or as a value.

Caution: Do not bind your selection results to a data source stack that already contains data. This will replace the contents of the data source stack with the selection result.

Binding the Selection Result dialog box

This dialog box contains the following elements:

Bind the selection result to this variable

Contains whatever you selected below.

Clear

Removes your current selection if you do not want to bind the selection result.

New variable

Opens the New Variable dialog box, where you can create a variable.

New data source stack

Opens the Stack Editor, where you can create a stack.

List of data source stacks and variables in your procedure

Contains a list of the existing stacks and variables in your procedure.

Either select a variable, or expand a data source stack and select a column.

Data Sources - Current Area

Lists the fields from the data sources used in this procedure.

Send the result as

Select Text to save the text value you entered in the List Source dialog box.

Select Value to save the value you entered in the List Source dialog box.


Top of page

x
Changing Combo Box or List Box Properties

When you select your combo box or list box, you will see a list of combo box or list box properties in the property sheet. Changing these properties will change what your edit box or multi-edit box looks like and what it does at run time.

Many of the styling properties can also be changed using a Cascading Style Sheet. For more information on Cascading Style Sheets, see Using Cascading Style Sheets.

Choose your combo box property or list box property based on the task you wish to perform:

If you want to change the contents of the combo box of list box, use the ListItems Property to open the List Source dialog box. For more information, see the List Source Dialog Box.

If you want to change the name of the combo box or list box that identifies it to the procedure, use the (Name) Property. For more information, see the (Name) Property.

If you want to assign the value selected by the end user to another variable, use the SelectedItem or SelectedItems Property to open the Binding the Selection Result dialog box. For more information, see Binding the Selection Result Dialog Box.

If you want to enable an end user to select more than one item in a list box, use the MultiSelection Property. This property does not apply to combo boxes. For more information, see the MultiSelection Property.

If you want to change the size or location of the combo box or list box, use the Bottom Property, Left Property, Right Property, Top Property, or use a style sheet. For more information, see the Bottom Property, Left Property, Right Property, and Top Property. You can also move or resize the combo box or list box directly in the form.

If you want to change the color of the combo box or list box, use the BackColor Property to determine the color of the box, the ForeColor Property to determine the color of the text in the box, or use a style sheet. For more information, see the BackColorOver Property and the ForeColor Property.

If you want to change the font in the combo box or list box, use a style sheet or use the Font Property. For more information, see the Font Property.

If you want to make the combo box or list box inactive or make it invisible, use the Enabled Property to determine whether the combo box or list box is active or not. If the combo box or list box is inactive, it will be dimmed out and nothing will happen when the end user clicks it. You can also use the Visible Property to determine whether the combo box or list box is visible to the end user or use a style sheet. For more information, see the Enabled Property and the Visible Property.

If you want to display a tooltip when the cursor is on the top of the combo box or list box, use the ToolTipText Property. For more information, see the ToolTipText Property.

If you want to assign a Help topic to the combo box or list box, use the Help Property. For more information, see Assigning Help to Your Forms and Controls.

If you want the end user to be able to tab to the combo box or list box, use the Tabstop Property. For more information, see the Tabstop Property.

If you want to move the combo box or list box to another layer, use the Layer Property. For more information, see Layering Controls.

If you want to control the display order of the combo box or list box when more than one control is overlaid, use the ZIndex Property. For more information, see the ZIndex Property.


WebFOCUS