How to change the selection mode (HTML)
[ This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation ]
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 |
---|---|
none |
Items cannot be selected. |
single |
Only one item may be selected. Clicking an item changes the selection to that item. |
multi |
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;