locked
Reference data in public listview

    Question

  • Hi,

    This is probably a very simply question to answer but I can't find a working example anywhere in the reference section of this site.  I am trying to set the value of a text box and set an item as selected in a drop down menu based on the item selected in a listview. 

    In a file called data.js I have an array which I have bound to a listview:

    var elements = ({ index: 1, title: "helium", picture: "img/pic.png" });    
    
    var elementList= new WinJS.Binding.List(elements);
    
    var publicElements =
       {
          itemList: elementList
       };
    WinJS.Namespace.define("Elements", publicElements);

    My question is if I know the key of the item in the listview I want to get, how do I get the value of the title using the public name (Elements)?
    Wednesday, November 14, 2012 9:11 PM

Answers

  • This should work: Elements.itemList.getAt(index).title

    MSDN reference for WinJS.Binding.List


    Tarek Ayna www.BluGraphingCalculator.com Blu Graphing Calculator is Calculator ReImagined for Windows 8


    Sunday, November 18, 2012 10:33 AM
  •  

    Hi VonSeraph,

    As Tarek suggested, what you should do is get the index of the item selected in ListView, and then use that index to locate the data source item in the datasource object ( the WinJS.Binding.List object). For ListView, the "oniteminvoked" event has provide the index via the event argument:

    #ListView.oniteminvoked event (Windows)
    http://msdn.microsoft.com/en-us/library/windows/apps/br211827.aspx

    for other event or condition (such as onselectionchanged event), you can try using the ListView.selection property to get all the selected items' indice.

    #ListView.onselectionchanged event (Windows)
    http://msdn.microsoft.com/en-us/library/windows/apps/br211849.aspx

    if you want to locate the certain item in your datasource through its key, you need to write a custom function which search the datasource list so as to find the certain item via its key property.

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Song Tian Tuesday, November 20, 2012 9:53 AM
    Monday, November 19, 2012 8:25 AM
    Moderator

All replies

  • This should work: Elements.itemList.getAt(index).title

    MSDN reference for WinJS.Binding.List


    Tarek Ayna www.BluGraphingCalculator.com Blu Graphing Calculator is Calculator ReImagined for Windows 8


    Sunday, November 18, 2012 10:33 AM
  •  

    Hi VonSeraph,

    As Tarek suggested, what you should do is get the index of the item selected in ListView, and then use that index to locate the data source item in the datasource object ( the WinJS.Binding.List object). For ListView, the "oniteminvoked" event has provide the index via the event argument:

    #ListView.oniteminvoked event (Windows)
    http://msdn.microsoft.com/en-us/library/windows/apps/br211827.aspx

    for other event or condition (such as onselectionchanged event), you can try using the ListView.selection property to get all the selected items' indice.

    #ListView.onselectionchanged event (Windows)
    http://msdn.microsoft.com/en-us/library/windows/apps/br211849.aspx

    if you want to locate the certain item in your datasource through its key, you need to write a custom function which search the datasource list so as to find the certain item via its key property.

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Song Tian Tuesday, November 20, 2012 9:53 AM
    Monday, November 19, 2012 8:25 AM
    Moderator