The ComboBox class represents a combo box control.
// define the combobox sample form
class MyForm extends Form {
combo = null;
textbox = null;
constructor(caption, x_pos, y_pos, width, height) {
// the constructor gets called when a new object is created;
// the super() function calls the constructor 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
this.combo = new ComboBox();
this.combo.add("Finch");
this.combo.add("Bluebird");
this.combo.add("Goose");
this.combo.add("Sparrow");
this.combo.add("Hummingbird");
this.combo.add("Duck");
this.combo.select(0);
// create a new line and textbox
const line = new Line(Line.Horizontal);
this.textbox = new TextBox();
this.textbox.setMultiline(true);
// connect the combobox events to the event handlers; these
// handlers will be called when the corresponding combo event
// is fired
this.combo.enterPressed.connect(this, this.onEnterPressed);
this.combo.selectionChanged.connect(this, this.onSelectionChanged);
this.combo.textChanged.connect(this, this.onTextChanged);
// connect the form resize event
this.sizeChanged.connect(this, this.onFormSizeChanged);
// add the combobox, line, and the textbox to the form
const layout_main = new BoxLayout(Layout.Vertical);
layout_main.addSpacer();
layout_main.add(this.combo, 0, Layout.Expand | Layout.Left | Layout.Right, 5);
layout_main.addSpacer(10);
layout_main.add(line, 0, Layout.Expand | Layout.Left | Layout.Right, 5);
layout_main.addSpacer(10);
layout_main.add(this.textbox, 1, Layout.Expand | Layout.Left | Layout.Right, 5);
layout_main.addSpacer();
// use layout_main for the main form layout
this.setLayout(layout_main);
}
onEnterPressed(sender, event_args) {
this.textbox.appendText(`Enter pressed. Text: ${event_args.text}\n`);
}
onSelectionChanged(sender, event_args) {
this.textbox.appendText(`Selection changed. Text: ${event_args.text}\n`);
}
onTextChanged(sender, event_args) {
this.textbox.appendText(`Text changed. Text: ${event_args.text}\n`);
}
onFormSizeChanged(sender, event_args) {
// when the form is resized, append text to the textbox
// with the new form size
const size = this.getSize();
this.textbox.appendText(`Form resized: (${size.width},${size.height})\n`);
this.layout();
}
}
// create a new combobox sample form; the class has to be declared
// before it is used, because a class declaration is not hoisted the
// way a function declaration is
const f = new MyForm("ComboBox Example", 0, 0, 400, 300);
f.center();
f.show();
Application.run(); Returns the index of the item that was added.
Adds an item, specified by text, to the list of items in the combo box.
Clears the combo box of all items.
Deletes an item with a specified index from the combo box.
Returns the index of the text that's found in the combo box and -1 if the text isn't found.
Finds the text item in the combo box and returns it's index if it's found and -1 if it isn't found.
The text item at the specified index.
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.
Returns the number of items in the combo box.
Returns the number of items in the combo box.
Returns the index of the selected item in the combo box.
Returns the index of the selected item in the combo box.
Returns the current text in the combo box.
Inserts a text item at a specified index.
Selects a combo box item at the specified index.
Sets the new text of a combo box item at a specified index.
Sets the current text in the combo box.