Gadgets > Rogue Wave Views Gadgets > Using Common Gadgets > Using IlvComboBox and IlvScrolledComboBox
 
Using IlvComboBox and IlvScrolledComboBox
The class IlvComboBox combines a text field with a list of predefined strings from which the user can choose. IlvScrolledComboBox displays a scrollbar when the list exceeds a certain number of choices. IlvComboBox class is a subclass of IlvTextField and IlvListGadgetItemHolder, and IlvScrolledComboBox class is a subclass of IlvComboBox.
A Combo Box
See Using IlvTextField.
This section covers the following topics:
*Setting a Combo Box as Noneditable
*Setting and Retrieving Items
*Changing or Retrieving the Selection
*Using Large Lists
*Setting the Number of Visible Items
*Localizing Combo Boxes
*Event Handling and Callbacks
Setting a Combo Box as Noneditable
By default, the text field part of the combo box can be edited, which means that you can change its content either by typing new text in it or pasting text from the clipboard. The member function IlvTextField::setEditable allows you to switch to read-only mode. In this mode, you can only choose a value from the menu.
The appearance of a combo box changes when it switches to read-only mode. Therefore, you must call the reDraw member function when changing the editing mode of a combo box.
Setting and Retrieving Items
Because IlvComboBox is a subclass of IlvListGadgetItemHolder, you must use the member functions of this class to modify the items of the combo box.
See IlvListGadgetItemHolder.
Changing or Retrieving the Selection
Because IlvComboBox is a subclass of IlvTextField, you can use the member functions of this class to set the text in a combo box or retrieve it.
See Setting and Retrieving Text.
You can also set the selected item in a combo box using an index number with setSelected and retrieve it with whichSelected.
Using Large Lists
Unlike IlvComboBox, the item list displayed by IlvScrolledComboBox has a fixed width corresponding to the combo box width. If the list contains large items, they might not fit in the text field and thus in the list. To modify this behavior, use the member function enableLargeList.
A Combo Box with Large List Enabled
Setting the Number of Visible Items
In a scrolled combo box, you can fix the number of visible items in the list. If all items are visible, there is no scrollbar.
To set the number of visible items, use the member function setVisibleItems.
Localizing Combo Boxes
The text appearing in a combo box can be localized. Only noneditable combo boxes can be localized.
See Localizing a Gadget.
Event Handling and Callbacks
When the user selects a new item with the mouse, uses the arrow keys, or enters new text and presses the Enter key, the Main callback of the combo box is invoked.
When the user opens the combo box list, the Open List callback is invoked. To set an Open List callback method, use the callback symbol returned by OpenListSymbol().
See Associating a Callback with a Gadget.

Version 6.1
Copyright © 2016, Rogue Wave Software, Inc. All Rights Reserved.