How to change the selection mode (HTML)
The ListView control's selectionMode property specifies how the user can select items in the list.
What you need to know
Technologies
Prerequisites
- We assume that you can create a ListView control. For more info, see the Add a ListView Quickstart.
Instructions
Change the selection mode
The selectionMode property supports these values, as defined by the SelectionMode enumeration:
| Term | Description |
|---|---|
|
Items cannot be selected. | |
|
Only one item may be selected. Clicking an item changes the selection to that item. | |
|
Multiple items may be selected. Clicking additional items adds them to the selection. |
To specify the selection mode in HTML, use the data-win-options attribute to set the selectionMode to a string representation of one of the allowed enumeration values, such as "none" or "single".
To specify the selection mode in HTML
-
This example sets the selection mode so that only a single item can be selected.
<div id="basicListView" data-win-control="WinJS.UI.ListView" data-win-options="{ itemDataSource : DataExample.itemList.dataSource, itemTemplate: select('#mediumListIconTextTemplate'), selectionMode: 'single'}"> </div>
To specify the selection mode in JavaScript, retrieve the control and set its selectionMode property.
To specify the selection mode in JavaScript
-
The next example sets the selection mode so that only a single item can be selected.
var myListView = document.getElementById("basicListView1").winControl; myListView.selectionMode = WinJS.UI.SelectionMode.single;
Related topics