ComboBox selection


I have a combo box, and a valueChanged event.

Is there any way to get

a) the currently selected item, or
b) the item ID of the currently selected combo box item, or
c) any other information about the current selection in the combo box, apart from the text


The combo box contains values from a database, and I’d prefer to refer to them by primary key rather than (potentially non-unique) text.

Thanks in advance


ComboBox.getValue() returns the “key” of the item. For example container.addItem(itemId) put’s the itemId as item key. Key can be of any type, so if you have put in a string, getValue() will return a string. You probably want to add a reference object instead, and use another property for displaying the caption.

For example with IndexedContainer, this is how you do it:

IndexedContainer container = new IndexedContainer();
container.addContainerProperty("caption", String.class, null);
Item item = container.addItem(myCar);
ComboBox select = new ComboBox("choose a car", container);