ListView.onselectionchanged event

0 out of 4 rated this helpful - Rate this topic

Occurs after the current selection changes.

Syntax


<div data-win-control="WinJS.UI.ListView" 
    data-win-options="{onselectionchanged : handler}">
</div>


function handler(eventInfo) { /* Your code */ }
 
// addEventListener syntax
listView.addEventListener("selectionchanged", handler);
listView.removeEventListener("selectionchanged", handler);
 
- or -

listView.onselectionchanged = handler;


Event information

SynchronousNo
BubblesYes
CancelableNo

Event handler parameters

eventInfo

Type: CustomEvent

An object that contains information about the event. The detail property of this object is null. To obtain the selected items, use the ListView.selection property.

Remarks

Warning  Don't make changes to the itemDataSource or groupDataSource in your event handler. Instead, call setImmediate from your event handler and pass it a function that makes the changes to the data source.

ListView events execute synchronously, so avoid performing expensive operations in your event handler. Performing expensive operations in your event handler can make the ListView seem unresponsive to the user. If you need the event handler to perform an expensive operation, call setImmediate from your event handler and pass it a function that performs the operation or perform the operation as an asynchronous operation. For more info about asynchronous programming, see Asynchronous programming in JavaScript.

This event doesn't fire if you delete the data source or reload it.

Setting event handlers declaratively (in HTML)

To set the event handler declaratively, it must be accessible to the global scope, and you must also call WinJS.Utilities.markSupportedForProcessing or WinJS.UI.eventHandler on the handler. You can make the handler accessible to the global scope by using WinJS.Namespace.define. For more information, see How to set event handlers declaratively.

Updating your AppBar when the selection changes

When the ListView selection changes or is the process of changing, consider the right way to update the your AppBar. For example, if the user selects a ListView item that contains an image, you might display a custom AppBar that shows image editing commands and set the AppBar control’s sticky property to true so that it won’t light dismiss. For info about creating custom AppBar controls, see Quickstart: Adding a custom app bar. For general guidelines for using AppBar controls (such as when to use sticky mode), see the Guidelines and checklist for app bars.

Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Namespace

WinJS.UI

Library

Ui.js

See also

ListView

 

 

Build date: 12/5/2012

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.