Like list widgets, combo-box widgets (CwComboBox) enable the user to select from a list of available items. A combo box also displays the last selected item in a text box above the list. Combo-box widgets can only have one item selected at a time. Combo-box widgets are created using the createComboBox:argBlock: convenience method.
There are two styles of combo boxes, specified by the comboBoxType resource:
As with the list widget, the items in the combo box are specified by the items resource. The application can add a singleSelection callback to be run whenever the selection changes. Several methods are provided for adding, deleting, and replacing items in the list.
The contents of the text part of the combo box can be set and retrieved using the setString: and getString methods.
The following example creates the drop down combo box shown at
right. Its items are set, the contents of the text box are initialized
to the first item, and a singleSelection callback is added.
| items shell combo | items := #('Item 1' 'Item 2' 'Item 3' 'Item 4'). shell := CwTopLevelShell createApplicationShell: 'shell' argBlock: [:w | w title: 'Combo Box Example']. |
![]() |
combo := shell createComboBox: 'combo' argBlock: [:w | w comboBoxType: XmDROPDOWN; items: items].
combo setString: items first. combo addCallback: XmNsingleSelectionCallback receiver: self selector: #singleSelect:clientData:callData: clientData: nil. combo manageChild. shell realizeWidget.