Combo Boxes Screen

These examples show how you can determine which combo box item was selected and other ways of manipulating the combo box control.

Example 1

To try this example, paste the following script onto a default Combo Box screen's On Next event (before the Screen.Next action). This script uses the first default combo box control, CTRL_COMBOBOX_01. The On Next event can be found on the Actions tab of the screen's properties.

strComboText = SessionVar.Expand("%Combo01%");

-- Determine which item was selected and display a dialog message.
if (strComboText == "Item A") then
    Dialog.Message("ComboBox", "Item A was selected.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
elseif (strComboText == "Item B") then
    Dialog.Message("ComboBox", "Item B was selected.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
elseif (strComboText == "Item C") then
    Dialog.Message("ComboBox", "Item C was selected.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
else
    Dialog.Message("ComboBox", "No item was selected. The default Item A was chosen.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end

This action script demonstrates how to check which of the three default combo box items were selected when leaving the screen and display a dialog message. This is accomplished by checking the value of the session variable that stores the item text of the selected item.

Example 2

This example requires you to paste code onto two different events on a new Combo Boxes screen.

To try this example, paste the following code onto the On Preload event of a Combo Boxes screen. This event can be found on the Actions tab of the screen's properties.

-- Remove all items from the second combo box control (CTRL_COMBOBOX_02).
DlgComboBox.RemoveItem(CTRL_COMBOBOX_02, -1);

-- Add two default items to the second combo box control.
DlgComboBox.AddItem(CTRL_COMBOBOX_02, "Item A Secondary One");
DlgComboBox.AddItem(CTRL_COMBOBOX_02, "Item A Secondary Two");

-- Select the first item in the second combo box's list.
DlgComboBox.SetProperties(CTRL_COMBOBOX_02, {Selected=1});

This action script first removes all contents from the second combo box control CTRL_COMBOBOX_02. It then adds two items and selects the first item in the list.

 

You can paste the following code onto the On Ctrl Message event of the same Combo Boxes screen, before the Screen.Next action. This event can be found on the Actions tab of the screen's properties.

-- Check to see if the selection changed message was fired.
if (e_MsgID == MSGID_ONSELCHANGED) then
    -- Check to see if the selection change was fired by the CTRL_COMBOBOX_01 control.
    if (e_CtrlID == CTRL_COMBOBOX_01) then
        -- Remove all items from the CTRL_COMBOBOX_02 control.
        DlgComboBox.RemoveItem(CTRL_COMBOBOX_02, -1);

        -- Check if "Item A" was selected in the first combo box.
        if (e_Details.Text == "Item A") then
            -- Add two items to the second combo box control related to "Item A"
            DlgComboBox.AddItem(CTRL_COMBOBOX_02, "Item A Secondary One");
            DlgComboBox.AddItem(CTRL_COMBOBOX_02, "Item A Secondary Two");
            -- Set selected state of the second combo box to the first item in the list.
            DlgComboBox.SetProperties(CTRL_COMBOBOX_02, {Selected=1});

        -- Check if "Item B" was selected in the first combo box.
        elseif (e_Details.Text == "Item B") then
            -- Add two items to the second combo box control related to "Item B".
            DlgComboBox.AddItem(CTRL_COMBOBOX_02, "Item B Secondary One");
            DlgComboBox.AddItem(CTRL_COMBOBOX_02, "Item B Secondary Two");
            -- Set selected state of the second combo box to the first item in the list.
            DlgComboBox.SetProperties(CTRL_COMBOBOX_02, {Selected=1});

        -- Check if "Item C" was selected in the first combo box.
        elseif (e_Details.Text == "Item C") then
            -- Add two items to the second combo box control related to "Item C".
            DlgComboBox.AddItem(CTRL_COMBOBOX_02, "Item C Secondary One");
            DlgComboBox.AddItem(CTRL_COMBOBOX_02, "Item C Secondary Two");
            -- Set selected state of the second combo box to the first item in the list.
            DlgComboBox.SetProperties(CTRL_COMBOBOX_02, {Selected=1});
        else
            -- Do nothing.
        end
    end
end

This example illustrates how you can use one combo box to control the contents of a second combo box.  When a selection is made in the first combo box CTRL_COMBOBOX_01, the second combo box is populated with items that relate to it. This allows you to create a submenu type design. This action script is run whenever a combo box selection is made on the screen, but reacts when a selection is made in the first combo box.