Developer Resources

ComboBox

Overview

The ComboBox class represents a combo box control.

Base Class

FormControl

Constructor

ComboBox(x_pos : Integer, y_pos : Integer, width : Integer, height : Integer)

Arguments

x_pos
The x position of the control.
y_pos
The y position of the control.
width
The width of the control.
height
The height of the control.

Events

ComboBox.enterPressed
Fired when enter has been pressed inside the combobox.
ComboBox.selectionChanged
Fired when the combobox's selection has changed.
ComboBox.textChanged
Fired when combobox's text has changed.

Methods

ComboBox.addItem
Adds a text item to the combo box.
ComboBox.clear
Clears the combo box of all items.
ComboBox.deleteItem
Deletes an item with a specified index from the combo box.
ComboBox.findItem
Finds the index of a string in the combo box.
ComboBox.getItem
Gets an item from the combo box based on the specified index.
ComboBox.getItemCount
Gets the number of items in the combo box.
ComboBox.getSelectedIndex
Gets the index of the selected item in the combo box.
ComboBox.getValue
Gets the current text in the combo box.
ComboBox.insertItem
Inserts a text item at a specified index.
ComboBox.selectItem
Selects a combo box item at the specified index.
ComboBox.setItem
Sets the text of a combo box item at the specified index.
ComboBox.setValue
Sets the current text in the combo box.

Inherited Methods

FormControl.captureMouse
Captures the mouse on this form control.
FormControl.disablePaint
Disables the window from redrawing itself.
FormControl.enablePaint
Enables the window to redraw itself.
FormControl.getBackgroundColor
Gets the background color of the form control.
FormControl.getClientSize
Gets the client size of the form control.
FormControl.getEnabled
Indicates whether or not a form control is enabled.
FormControl.getFont
Gets the default font for the text of form control.
FormControl.getForegroundColor
Gets the foreground color of the form control.
FormControl.getMaxSize
Gets the maximum size of the form control.
FormControl.getMinSize
Gets the minimum size of the form control.
FormControl.getMousePosition
Gets the mouse position relative to this form control.
FormControl.getNativeHandle
Gets the native handle of the window/control
FormControl.getPosition
Gets the position of a form control.
FormControl.getSize
Gets the size of the form control.
FormControl.invalidate
Invalidates a form control, which will cause it to be repainted on the next paint event.
FormControl.refresh
Refreshes a form control, which immediately repaints the entire form control.
FormControl.releaseMouse
Releases the mouse from being captured on this form control.
FormControl.setBackgroundColor
Sets the background color of the form control.
FormControl.setClientSize
Sets the client size of a form control.
FormControl.setEnabled
Enables or disables the form control.
FormControl.setFocus
Sets the focus to the form control.
FormControl.setFont
Sets the default font for the text of the form control.
FormControl.setForegroundColor
Sets the foreground color of the form control.
FormControl.setMaxSize
Sets the maximum size of a form control.
FormControl.setMinSize
Sets the minimum size of a form control.
FormControl.setPosition
Sets the position of a form control relative to the the form control's parent.
FormControl.setSize
Sets the size of a form control.
FormControl.show
Shows or hides the form control.
FormControl.update
Updates a form control, which will immediately repaint any invalid areas.

Example

// create a new combobox sample form
var f = new MyForm("ComboBox Example", 0, 0, 400, 300);
f.center();
f.show();
Application.run();


// define the combobox sample form
class MyForm extends Form
{
    var m_combo;
    var m_line;
    var m_textbox;
    var m_layout;

    function MyForm(caption, x_pos, y_pos, width, height)
    {
        // MyForm() gets called when a new object is created;
        // the super() function calls the contructor on the
        // base class, which in this case is Form since MyForm
        // extends Form
        super(caption, x_pos, y_pos, width, height);
    
        // create a new combobox; add some items to the
        // combobox and select the first item in the list
        m_combo = new ComboBox;
        m_combo.add("Finch");
        m_combo.add("Bluebird");
        m_combo.add("Goose");
        m_combo.add("Sparrow");
        m_combo.add("Hummingbird");
        m_combo.add("Duck");
        m_combo.select(0);
        
        // create a new line and textbox
        m_line = new Line(Line.Horizontal);
        m_textbox = new TextBox();
        m_textbox.setMultiline(true);

        // connect the combobox events to the event handler; these 
        // handlers will be called when the corresponding combo event 
        // is fired
        m_combo.enterPressed.connect(this, onEnterPressed);
        m_combo.selectionChanged.connect(this, onSelectionChanged);
        m_combo.textChanged.connect(this, onTextChanged);
        
        // connect the form resize event
        this.sizeChanged.connect(this, onFormSizeChanged);

        // add the combobox, line, and the textbox to the form
        m_layout = new BoxLayout(Layout.Vertical);
        m_layout.addSpacer();
        m_layout.add(m_combo, 0, Layout.Expand | Layout.Left | Layout.Right, 5);
        m_layout.addSpacer(10);
        m_layout.add(m_line, 0, Layout.Expand | Layout.Left | Layout.Right, 5);
        m_layout.addSpacer(10);
        m_layout.add(m_textbox, 1, Layout.Expand | Layout.Left | Layout.Right, 5);
        m_layout.addSpacer();
        
        // use m_layout for the main form layout
        setLayout(m_layout);
    }

    function onEnterPressed(sender, event_args)
    {
        m_textbox.appendText("Enter pressed. Text: " + event_args.text + "\n");
    }

    function onSelectionChanged(sender, event_args)
    {
        m_textbox.appendText("Selection changed. Text: " + event_args.text + "\n");
    }
    
    function onTextChanged(sender, event_args)
    {
        m_textbox.appendText("Text changed. Text: " + event_args.text + "\n");
    }    
    
    function onFormSizeChanged(sender, event_args)
    {
        // when the form is resized, append text to the textbox
        // with the new form size
        var size = "(" + getSize().width + "," + getSize().height + ")";
        m_textbox.appendText("Form resized: " + size + "\n");
        layout();        
    }    
}

ComboBox.addItem

function ComboBox.addItem(text : String) : Integer

Arguments

text
The text to add to the list of combo box items.

Returns

Returns the index of the item that was added.

Description

Adds an item, specified by text, to the list of items in the combo box.

ComboBox.clear

function ComboBox.clear()

Description

Clears the combo box of all items.

ComboBox.deleteItem

function ComboBox.deleteItem(index : Integer)

Arguments

index
The index of the item to delete from the list of items in the combo box.

Description

Deletes an item with a specified index from the combo box.

ComboBox.findItem

function ComboBox.findItem(text : String) : Integer

Arguments

text
The text to find in the combo box.

Returns

Returns the index of the text that's found in the combo box and -1 if the text isn't found.

Description

Finds the text item in the combo box and returns it's index if it's found and -1 if it isn't found.

ComboBox.getItem

function ComboBox.getItem(index : Integer) : String

Arguments

index
The index of the item in the combo box to return.

Returns

The text item at the specified index.

Description

Returns the text item at the specified index. If index isn't specified, then the currently selected string is returned, which may include the item that's currently being entered in the combo box before it actually becomes part of the list.

ComboBox.getItemCount

function ComboBox.getItemCount() : Integer

Returns

Returns the number of items in the combo box.

Description

Returns the number of items in the combo box.

ComboBox.getSelectedIndex

function ComboBox.getSelectedIndex() : Integer

Returns

Returns the index of the selected item in the combo box.

Description

Returns the index of the selected item in the combo box.

ComboBox.getValue

function ComboBox.getValue() : String

Description

Returns the current text in the combo box.

ComboBox.insertItem

function ComboBox.insertItem(text : String, index : Integer)

Arguments

text
The text item to add to the combo box.
index
The index at which to insert the text in the combo box.

Description

Inserts a text item at a specified index.

ComboBox.selectItem

function ComboBox.selectItem(index : Integer)

Arguments

index
The index of the item to select in the combo box.

Description

Selects a combo box item at the specified index.

ComboBox.setItem

function ComboBox.setItem(index : Integer, text : String)

Arguments

index
The index of the item in the combo box for which to change the text.
text
The new text for the item at the specified index.

Description

Sets the new text of a combo box item at a specified index.

ComboBox.setValue

function ComboBox.setValue(text : String)

Arguments

text
The text to set in the combo box.

Description

Sets the current text in the combo box.