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.

Creating combo boxes

// Create an empty combo box

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

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), $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), $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);

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);
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 listbox 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);
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));
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