How to fetch selected item of ListView in HTML based Windows 8 Metro Application

I had tough time get the value of selected item of a ListView. So in this post I am sharing the code snippet required to fetch selected item from the ListView.

Read this article for ListView Binding with Grouping and Semantic Zoom in Windows 8 JavaScript Metro Application

I strongly suggest you to read the above article for more detail on ListView. If you continue with above article and want to get the value of selected item you can do that as below,


lstMovies = document.getElementById("movieListView").winControl;  
lstMovies.addEventListener("iteminvoked", function (e) {
                e.detail.itemPromise.then(function (invokedItem) {


                    var titleOfData = invokedItem.data.title;
                    var selecteplayerImg = invokedItem.data.picture;
                });
            }, false);


In above code snippet

  • lstMovies is name of the ListView.
  • Iteminvoked is name of the event. This event gets fire when an item in the ListView is being selected.
  • There are two data bind to the List View item. They are Title and Picture. Any data can be fetched as following snippet. invokedItem is parameter of itemPromise.

image

Title and Picture are properties of the datasource bind to the ListView.

In this way you can fetch selected item from ListView in HTML based Windows 8 Metro Application. I hope this post is useful. Thanks for reading!

Awarded with Microsoft MVP Award: 3rd time in Row

 

To My Blog Readers,

For me, “Microsoft MVP Award is not an Award rather it is a Responsibility

image

I am happy to announce to all my readers that I have been awarded as Microsoft MVP 3rd Time in row. This time also I have been awarded in discipline Connected System Development (CSD).

From 1st April 2011 to 31st March 2012

image

I would take this opportunity to thank you my dear reader. I promise to serve and help you more in learning and developing throughout the coming years.

To be in touch with me FOLLOW ME ON TWITTER or CONNECT AT FACEBOOK PAGE

Any of your feedback is much appreciated.

Thanks with Regards

Dhananjay Kumar