## ComboBox class

A ComboBox is a collapsible list of selectable items.

To create a combo box use the wb_create_control() function using ComboBox as the class parameter.

A normal (read-only) combo box needs the WBC_READONLY flag. If you omit this flag the resulting combo box will have an editable field just like an EditBox control.

NOTE: Windows does not always provide enough space for the attached list box. See "setting the height of a combo box" below.

# Creating combo boxes

    // Create an empty combo box

    wb_create_item($window, ComboBox, "", 10, 10, 100, 90, ID_COMBO, WBC_READONLY);

After creating the combo box, you can assign values to the control in several ways:

1) By creating an array to store the item names and using wb_set_text() to assign them to the control:

    $a_combo = array("Line1", "Line2", "Line3", "Line4");

    // Assign values to combo box control
    wb_set_text(wb_get_control($window, ID_COMBO, WBC_READONLY), $a_combo);

2) By assigning it a string with items separated by a line break (\n) or line feed/line break sequence: (\r\n):

    $s_combo = "Line1\nLine2\nLine3";       \\ Or "Line1\r\nLine2\r\nLine3"

    // Assign values to combo box control
    wb_set_text(wb_get_control($window, ID_COMBO, WBC_READONLY), $s_combo);

3) By including the desired items when creating a control:

    wb_create_item($window, ComboBox, "Line1\nLine2\nLine3", 10, 10, 100, 90, ID_COMBO, WBC_READONLY);

# Setting the height of a combo box

In certain cases, a combo box will not appear to drop down. For an example, see the code below.

    wb_create_control($mainwin, ComboBox, "", 80, 60, 130, 20, IDC_COMBO, WBC_READONLY);
    wb_set_text($combo, "Item1\r\nItem2\r\nItem3");

The code above will generate a combo box which will not drop down in Windows 2000, Windows 98 or Windows Me. It seems that these versions of Windows expect you to tell them the total height of the list box that is included in the control. To solve the problem, change the height to a greater value, say, 90 pixels:

    wb_create_control($mainwin, ComboBox, "", 80, 60, 130, 90, IDC_COMBO, WBC_READONLY);
    wb_set_text($combo, "Item1\r\nItem2\r\nItem3");

This can also be done after the control is created using wb_set_size():

`$size = wb_get_size(wb_get_control($mainwin, IDC_COMBO, WBC_READONLY)); wb_set_size(wb_get_control($mainwin, IDC_COMBO), $size[0], 90);`

# Setting and retrieving information

To associate an integer value with a given item, use wb_set_value(). Set item to the desired item index, or leave it blank (or set it to -1) to associate the value to the currently selected item.

To retrieve the index of the currently selected item, call wb_get_selected(). Use wb_get_value() to retrieve the integer value associated to the specified item, or leave item empty (or set it to -1) to retrieve the value of the currently selected item.

# See also

wb_create_control
wb_get_selected
wb_get_value
wb_set_text
wb_set_value
ListBox class
Control classes