The ComboBox control combines an input element with a drop-down list. You can use it to select and/or edit strings or objects from lists. The control automatically completes entries as the user types, and allows users to show a drop-down list with the items available.
Some important properties related to Combobox are:
In the example below, we have created and populated a ComboBox using an object array and defining the displayMemberPath.
<div id="theComboObject"></div>
import * as wijmo from '@grapecity/wijmo';
import * as input from '@grapecity/wijmo.input';
import { getCountries, getData } from './data';
function init() {
// select an item (object)
var theComboObject = new input.ComboBox('#theComboObject', {
displayMemberPath: 'country',
itemsSource: getData()
});
}
User can dynamically add items to the ComboBox itemsSource by setting the isEditable property to True and then handling the lostFocus event. As soon as user types in a value that does not exist in the itemsSource and moves the focus away from the control, the lostFocus event appends the typed item to the array assigned as the itemsSource of the control.
<div id="theCombo"></div>
import * as wijmo from '@grapecity/wijmo';
import * as input from '@grapecity/wijmo.input';
function init() {
let countries = new wijmo.ObservableArray(['US', 'Germany', 'UK', 'Japan', 'Italy', 'Greece']);
//
new input.ComboBox('#theCombo', {
itemsSource: countries,
isEditable: true,
lostFocus: lostFocus
});
// add item to the list when a control loses focus
function lostFocus(sender) {
let item = sender.text;
if (item && countries.indexOf(item) < 0) {
countries.push(item);
}
}
}
Submit and view feedback for