Blitz3D+ Command Reference

NextSelectedGadgetItem ( listbox[,after] )

Parameters

listbox - list box gadget

after (optional) - item index to continue searching after; -1 starts from the beginning (default)

Description

Returns the next selected list box item after a given index, or -1 when there are no more.

Requires Extended language mode.

This is the enumeration half of multi-selection. A list box created with style 1 lets the user Ctrl-click and Shift-click several items; to walk them all, in ascending order and without any allocations:

index=NextSelectedGadgetItem(listbox)
While index<>-1
    ; ... act on item index ...
    index=NextSelectedGadgetItem(listbox,index)
Wend

On a single-select list box it simply returns the one selected item (or -1). Passing an after value below -1 or beyond the last item stops with a runtime error.

Multi-select $401 events are replaceable snapshots and EventData only carries the focused item, so enumerating like this is the reliable way to read the complete selection when an event arrives.

See it working in the selection and context menus sample.

See also: CountSelectedGadgetItems, GadgetItemSelected, SetGadgetItemSelected, SelectedGadgetItem, CreateListBox.

Index