ListBox Selection
This article describes the ListBox selection feature, including the available selection modes, and how to use the SelectedItems parameter.
Selection Modes
The ListBox component provides users two ways to select items. This depends on the value of the SelectionMode parameter, which expects a member of the ListBoxSelectionMode enum.
| Selection Mode | Description |
|---|---|
Single | Users can select only one ListBox item. They can change the selected item, but cannot deselect the selected one. You can use a custom toolbar button to clear the selection. See the example below. |
Multiple | Users can select any number of items. The ListBox supports selection of adjacent items with Shift or non-adjacent items with Ctrl (Cmd on a Mac). Use mouse clicks or the arrow keys, as described on the ListBox Keyboard Navigation demo. |
SelectedItems Parameter
The SelectedItems parameter of the ListBox supports two-way binding. In this case, the component will update the SelectedItems parameter value automatically when the user changes the current selection. If you use SelectedItems with one-way binding, you must subscribe to the SelectedItemsChanged event to update the SelectedItems parameter value manually on each user selection.
The ListBox
SelectedItemsparameter must be defined asIEnumerable<T>in the application. Unlike theDataparameter, it cannot be aList<T>, because the built-inSelectedItemsChangedhandler that is used with two-way binding is defined in the ListBox source code asEventCallback<IEnumerable<T>>.
Example
Using ListBox SelectionMode and Custom Deselect Tool
Next Steps
- Connect Multiple ListBoxes
- Enable ListBox drag-and-drop
- Implement ListBox templates
- Handle ListBox events