On Mar 16, 8:24 pm, Dave <[email protected]> wrote:
> I'm attempting to get multiple selected items from a ListBox
>
> My setup code is:
>
> final ListBox listBox = new ListBox(true);
> listBox.addItem("Item 1", "1");
> listBox.addItem("Item 2", "2");
> listBox.addItem("Item 3", "3");
>
> In the onClick event of a button on my panel I want to get the
> selected items. I have seen suggestions to iterate over all the
> items, calling the isItemSelected() method for each item to determine
> whether it’s selected. However I do not see any methods available on
> ListBox to get the list of items. Obviously I could add a listener to
> the listBox to capture when someone selects or unselects an item but
> there must be an easier way to get all of the selected items in a
> multiselect ListBox
You won't get a "list of items", actually the ListBox /is/ the list of
items.
List<String> selectedValues = new ArrayList<String>();
for (int i = 0, l = listBox.getItemCount(); i < l; i++) {
if (listBox.isItemSelected(i)) {
selectedValues.add(listBox.getValue(i));
}
}
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.