Control | +--ComboBoxpublic class ComboBox
Encapsulates a standard Windows combo box. This class supports the three basic combo box styles: a drop-down combo box, including an editable text portion; a drop-down list, with a read-only text portion; and a simple combo box, which is a drop-down combo box that is always in a drop-down state, with editable text. To add items to the combo box, you pass in an array of objects. Internally, the ComboBox class calls the toString method on the objects you pass in and inserts them into the combo box.
Constructors
Name | Description |
---|---|
ComboBox() | Creates a new ComboBox control with a default style of ComboBoxStyle.DROPDOWN. |
Methods
Name | Description |
---|---|
addItem(Object item) | Adds an item to the combo box and retrieves the index of the new item. |
addOnDrawItem(DrawItemEventHandler value) | Adds an event handler for the onDrawItem event notification. |
addOnDropDown(EventHandler value) | Adds an event handler for the onDropDown event notification. |
addOnMeasureItem(MeasureItemEventHandler value) | Adds an event handler for the onMeasureItem event notification. |
addOnSelectionChange(EventHandler value) | Adds an event handler for the onSelectionChange event notification. |
beginUpdate() | Temporarily disables any redrawing of the combo box. |
endUpdate() | Re-enables redrawing to a combo box (temporarily suspended by a previous call to beginUpdate. |
findItem(Object item) |
Note This method is obsolete. |
findString(String s) | Retrieves the zero-based index of first occurrence of the an item that begins with the specified text. |
findString(String s, int startIndex) | Retrieves the zero-based index of the first occurrence of an item that begins with the specified text, beginning the search at the specified index. |
findStringExact(String s) | Retrieves the zero-based index of the first occurrence of the specified item. |
findStringExact(String s, int startIndex) | Retrieves the zero-based index of the first occurrence of the specified item. |
getCreateParams() | Topic under construction. |
getDrawMode() | Retrieves the drawing mode of the combo box. |
getDroppedDown() | Retrieves a boolean indicating whether the drop-down portion of the combo box is currently displayed. |
getItem(int index) | Retrieves the item at the specified index. |
getItemCount() | Retrieves the number of items in the combo box. |
getItemHeight() | Retrieves the height of each item in the combo box. |
getItemHeight(int index) | Returns the height, based on the specified index, of the given item in a combo box in which the DrawMode.OWNERDRAWVARIABLE style is set. |
getItems() | Retrieves all the items in the combo box, and returns the items in an array of objects. |
getMaxDropDownItems() | Retrieves the maximum number of items that can be displayed in the drop-down portion of the combo box. |
getMaxLength() | Retrieves the maximum length of the text the user can type into the edit control of a combo box. |
getSelectedIndex() | Retrieves the index of the currently selected item in the combo box. |
getSelectedItem() | Retrieves the object that is currently selected in the combo box. |
getSelectedText() | Retrieves the text of the currently selected item. |
getSelectionEnd() | Retrieves the zero-based index of the last character in the combo box selection. |
getSelectionStart() | Retrieves the index of the first character of the currently selected text. |
getSorted() | Retrieves a boolean value that indicates whether the contents of the combo box are sorted. |
getStyle() | Retrieves the style of the combo box. |
insertItem(int index, Object item) | Inserts an item into the combo box at the given index. |
removeAll() | Clears the combo box. |
removeItem(int index) | Removes the item at the specified index. |
removeOnDrawItem(DrawItemEventHandler value) | Removes the specified handler for the onDrawItem event. |
removeOnDropDown(EventHandler value) | Removes the specified handler for the onDropDown event. |
removeOnMeasureItem(MeasureItemEventHandler value) | Removes the specified handler for the onMeasureItem event. |
removeOnSelectionChange(EventHandler value) | Removes the specified handler for the onSelectionChange event. |
select(int start, int end) | Selects the text in the specified range. |
selectAll() | Selects all the text in the editable portion of the combo box. |
setDrawMode(int value) | Sets the drawing style of the combo box. |
setDroppedDown(boolean value) | Displays or hides the drop-down portion of the combo box. |
setItem(int index, Object item) | Initializes the specified index. |
setItemHeight(int value) | Sets the height of an item in a combo box of style ComboBoxStyle.OWNERDRAWFIXED. |
setItems(Object[] value) | Initializes a combo box based on the contents of an array of objects. |
setMaxDropDownItems(int value) | Sets the maximum number of items that can be displayed in the dropdown portion of the combo box. |
setMaxLength(int value) | Sets the maximum allowable length of the text in the editable portion of the combo box. |
setSelectedIndex(int index) | Selects the specified item. |
setSelectedText(String value) | Replaces the currently selected text with the specified text. |
setSelectionEnd(int value) | Specifies the zero-based index of the last character of a text selection in the ComboBox control. |
setSelectionStart(int value) | Specifies the zero-based index of the first character of a text selection in the Edit control. |
setSorted(boolean value) | Specifies whether the items in the combo box should be sorted. |
setStyle(int value) | Sets the style of the combo box. |
Creates a new ComboBox control with a default style of ComboBoxStyle.DROPDOWN. To change the style of the ComboBox, use the setStyle method with one of the constants defined in the ComboBoxStyle class.
Returns the zero-based index of the added item.
Adds an item to the combo box and retrieves the index of the new item. For an unsorted combo box, the item is added to the end of the existing list of items. For a sorted combo box, the item is inserted into the list according to its sorted position.
RunTimeException thrown if there is insufficient space in which to store the new item.
Adds an event handler for the onDrawItem event notification. The onDrawItem event is fired for combo boxes whose draw mode setting is DrawMode.OWNERDRAWFIXED or DrawMode.OWNERDRAWVARIABLE. The DrawItemEventHandler object passed as a parameter to this event handler contains a Graphics object that you use to paint the item. Duplicate calls to the addOnDrawItem method are not filtered out by the ComboBox class.
Adds an event handler for the onDropDown event notification. This event is fired when the drop-down portion of the combo box is displayed. Duplicate calls to addOnDropDown are not filtered out by the ComboBox class.
Adds an event handler for the onMeasureItem event notification. This event is fired for list boxes whose drawMode property is set to DrawMode.OWNERDRAWFIXED or DrawMode.OWNERDRAWVARIABLE. Within this onMeasureItem event, you use the MeasureItemEvent object passed to the handler to notify Windows of the size of a given item in the combo box. If the DrawMode for this combo box is OWNERDRAWFIXED, this event is sent only once. Duplicate calls to addOnMeasureItem are not filtered out by the ComboBox class.
Adds an event handler for the onSelectionChange event notification. This event is fired when the user changes the selection in the combo box. Duplicate calls to this method are not filtered out by the ComboBox class.
Temporarily disables any redrawing of the combo box. A call to beginUpdate must be followed by a call to endUpdate. Following the call to beginUpdate, any redrawing that would result by operations performed on the combo box is deferred until the call to endUpdate.
Re-enables redrawing to a combo box (temporarily suspended by a previous call to beginUpdate. All redrawing of the combo box occurs after the call to endUpdate.
Note This method is obsolete.
Returns the zero-based index of the first occurrence of the specified item if the item exists; otherwise, returns -1.
Retrieves the zero-based index of first occurrence of the an item that begins with the specified text. The search for this item starts at the beginning of the list of items in the combo box, and the search is case-insensitive.
Returns the zero-based index of the first item that begins with the specified text if it exists; otherwise, returns -1.
Retrieves the zero-based index of the first occurrence of an item that begins with the specified text, beginning the search at the specified index. This search is case-insensitive.
Returns the zero-based index of the first occurrence of the item if the item exists; therwise, returns -1.
Retrieves the zero-based index of the first occurrence of the specified item. The search for the item begins at the beginning of the list of items stored by the combo box. The specified string must match exactly the string in the combo box, except in regard to case.
Returns the zero-based index of the first string (after the specified index) that matches the search string if the string exists; otherwise, returns -1.
Retrieves the zero-based index of the first occurrence of the specified item. The search for the item begins at the specified index. The specified string must match the string in the combo box exactly, except in regard to case.
Topic under construction.
Returns an enumeration constant defined DrawMode class.
Retrieves the drawing mode of the combo box. The DrawMode property controls whether the control is drawn by Windows or by the user.
Returns true if the drop-down portion of the combo box is displayed; otherwise, returns false.
Retrieves a boolean indicating whether the drop-down portion of the combo box is currently displayed.
Returns the item at the index specified.
Retrieves the item at the specified index.
InvalidArgument thrown if the specified index is less than zero or exceeds the number of items in the combo box.
Returns an integer that specifies the number of items in the combo box.
Retrieves the number of items in the combo box.
Returns the height of the items in the combo box.
Retrieves the height of each item in the combo box. For all DrawModes except OWNERDRAWVARIAIBLE, all items have the same height. For OWNERDRAWVARIABLE combo boxes, each item may have a different height.
Returns the height of the specified item in pixels,.
Returns the height, based on the specified index, of the given item in a combo box in which the DrawMode.OWNERDRAWVARIABLE style is set. This method should not be called for combo boxes in which the item height is fixed.
Returns an array with all the items currently in the combo box.
Retrieves all the items in the combo box, and returns the items in an array of objects.
Returns the maximum number of items that can be displayed.
Retrieves the maximum number of items that can be displayed in the drop-down portion of the combo box. This number can be between 1 and 100.
Returns the maximum lengh of the text.
Retrieves the maximum length of the text the user can type into the edit control of a combo box.
Returns the zero-based index of the currently selected item.
Retrieves the index of the currently selected item in the combo box.
Returns the currently selected object if an item is selected; otherwise, returns null.
Retrieves the object that is currently selected in the combo box.
Returns the text of the currently selected item.
Retrieves the text of the currently selected item.
Returns the zero-based index of the last character in the current selection.
Retrieves the zero-based index of the last character in the combo box selection.
Returns the zero-based index of the start of the first character in current selection.
Retrieves the index of the first character of the currently selected text.
Returns true if the list is sorted; otherwise, returns false.
Retrieves a boolean value that indicates whether the contents of the combo box are sorted.
Returns the style of the combo box.
Retrieves the style of the combo box. The returned value is one of the enumeration constants defined in the ComboBoxStyle class.
Returns the index at which the item was inserted.
Inserts an item into the combo box at the given index.
Clears the combo box.
Removes the item at the specified index.
Removes the specified handler for the onDrawItem event. If there are duplicate entries, all the handlers are removed.
Removes the specified handler for the onDropDown event. If there are duplicate entries, all the handlers are removed.
Removes the specified handler for the onMeasureItem event. If there are duplicate entries, all the handlers are removed.
Removes the specified handler for the onSelectionChange event. If there are duplicate entries, all the handlers are removed.
Selects the text in the specified range.
Selects all the text in the editable portion of the combo box.
Sets the drawing style of the combo box. By setting the drawing mode of the combo box, you specify whether the combo box is owner-draw and whether all items displayed in the combo box are of the same height.
InvalidEnumArgument yhrown if the specified value is less than DrawMode.MIN or exceeds DrawMode.MAX.
Displays or hides the drop-down portion of the combo box.
Initializes the specified index. If the item at the specified index already contains data, this data is lost.
Sets the height of an item in a combo box of style ComboBoxStyle.OWNERDRAWFIXED. If the style of a combo box is DrawMode.NORMAL, a call to this method is ignored.
Initializes a combo box based on the contents of an array of objects. All values currently stored in the combo box are lost.
Sets the maximum number of items that can be displayed in the dropdown portion of the combo box. This value can be between 1 and 100.
IllegalArgumentException thrown if the specified value is less than zero or more than one hundred.
Sets the maximum allowable length of the text in the editable portion of the combo box.
Selects the specified item.
Replaces the currently selected text with the specified text.
Specifies the zero-based index of the last character of a text selection in the ComboBox control.
Specifies the zero-based index of the first character of a text selection in the Edit control.
Specifies whether the items in the combo box should be sorted. By default, items in a ComboBox control are not sorted.
Sets the style of the combo box.