More documentation about the manipulation of ListView data (in the simple case).


  • I am trying to convert an application that worked in the Developer Preview but is now broken.

    The current problem is the change from the use of ArrayDataSource to BindingList object in the sourcing and manipulation of data in a ListView.  Through a combination of Build videos, samples and the sparse API documentation I was able to get things working in the DP, but now I am a bit lost.  Specifically, the use of indices vs keys and when to access the data in the ListView items vs the DataSource.  The BindingList seems to work differently.

    The application is super simple.  Very small array of objects (in memory) that I want to display in a ListView, then add, delete and update these items.  I've looked at the updated sample but it seems overly complex to me and I keep wondering why the programmer did things in a certain way.  Moreover, I always wonder if the example is for a case which is meant to cover large datasets and that is overkill for my needs.  I am having a problem inferring how to translate the sample into my application without some more explanation.

    Is there some documentation, blog or forum post that can shed more light on how to manipulate data that is to be displayed in a ListView?  I'm sure I could crack it eventually, but if there is more information out there, I would love to see it.

    Thursday, March 29, 2012 3:28 PM


All replies

  • Hi Jr,

    Have you seen this documentation on migrating your code from Developer Preview to Consumer Preview?  It should list the changes you need to make for each API you are using in your

    Migrating Windows 8 Developer Preview code to Consumer Preview


    Jeff Sanders (MSFT)

    Thursday, March 29, 2012 5:31 PM
  • Thank you for responding.  I have seen it but I guess I don't fully comprehend.  I presume the relevant section is on Page 209  DataSource API changes.  Supposedly, the use of BindingList is to 'simplify' the ListView programming in some situations but how?  The sample application seems to have as much code as it did in the DS examples.

    Suppose I have an array of objects Qdata and listView LV.  I can hook the array to the listView with:

    document.getElementById("LV").winControl.itemDataSource = new WinJS.Binding.List(Qdata);  //so far so good.  With the correct template, the data appears.

    now, in another section of code I want to add a newItem to the top of the listView:

    var promises = [];

    var ds = document.getElementById("LV").winControl.itemDataSource;


    promises.push(ds.insertAtStart(newItem.key, newItem)); //key is a unique attribute for each item




    This will update the ListView but does it also change the array that is the dataSource, Qdata?  That seemed to be the case when using ArrayDataSource in the DP but not so when using BindingList (unless I've made another mistake somewhere).  Also, this seems to be using the ListDataSource API that the migration document says is 'overly complicated' but is used in the sample.

    I see there appears to be an API for operating on the WinJS.Binding.List object (push, pop etc) is that preferred?  There seems to be no method for adding to the top of the list (required) or to change an item directly.

    Then there is an API for adding directly to the ListView?


    I can't find this in the API for ListView.

     Too many choices.


    • Edited by jrboddie Saturday, March 31, 2012 9:20 PM
    Thursday, March 29, 2012 6:43 PM
  • The ListView sample shows inserting, moving and deleting items using various data sources: http://code.msdn.microsoft.com/windowsapps/ListView-custom-data-4dcfb128

    Is that sufficient for your purposes?


    Jeff Sanders (MSFT)

    • Marked as answer by jrboddie Friday, March 30, 2012 2:35 PM
    Friday, March 30, 2012 1:33 PM
  • Jeff,

    I'm sure I can make my app work from this sample, which I have already studied.  I miss the level of documentation that we have in .Net where nearly every method or property has a simple example of its application.  In my opinion, some of the samples are overly complex and try to demonstrate too many capabilities without sufficient comments or supporting documentation.  The videos from Build were helpful for the DP but are now out of date.


    Friday, March 30, 2012 2:40 PM
  • Hi Jim,

    Sorry about the documentation, I feel your pain trust me.  I have been relying heavily on the samples and inspecting the WinJS libraries.  It will get better as we progress!  As you have seen APIs have changed and the writers are busy at getting all this updated.


    Jeff Sanders (MSFT)

    Friday, March 30, 2012 2:56 PM