locked
How to deselect an item in a list through JS RRS feed

  • Question

  • Hi there,

    So I have my listview and when you click an item it gets the default purple border. A button is rendered on the screen when you select an item. If you click the item a second time in the listview the purple border will go away. I want to be able to click the rendered  button that showed up when I initially clicked the item, and clicking that button make the border go away. I'm not sure how to do that though. My thinking is to have a var set to null, and when I click an item in the listview have the var change to the index of whichever item I selected. Then when I click the button change the border property of that index.

    I'm not sure if this is a good approach/how to do it exactly.

    Thanks!


    Friday, May 3, 2013 6:04 PM

Answers

  • As other members have suggested, you can use ListView.selection property to control the selection. ListView.selection property is of WinJS.UI.ISelection type. You can call ListView.selection.set(-1) so as to clear the selection.

    #WinJS.UI.ISelection interface
    http://msdn.microsoft.com/en-us/library/windows/apps/hh872204.aspx

     


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

    • Proposed as answer by Can Bilgin Tuesday, May 7, 2013 8:48 AM
    • Marked as answer by ZachAtttack Tuesday, May 7, 2013 6:34 PM
    Monday, May 6, 2013 1:46 AM
    Moderator

All replies

  • Hi,

    Below is the approach what I can think of :

    While binding data to the list view data source the data should be bound as Binding object (WinJS.Binding.as). The data should have a property called "IsSelected".

    1. On ItemInvoked function , get the item from the binding list by index and then set it's IsSelected property to true. Also store the index in some global variable.

    2. On next Item invoked or the button clicked, get the item by using the global index that is stored. Set it's IsSelected property to false.

    You should be able to use a converter for the border color to change based on the IsSelected Value .

    Let me know if you need further help.

    - Girija

    Friday, May 3, 2013 6:15 PM
  •  

    Also another option is listvw.selection.clear();

    or

    listvw.selection.getItems.then( function (items){ for (j in items){..} ..})

    where listvw is the listview.


    karthika

    Sunday, May 5, 2013 12:24 AM
  • As other members have suggested, you can use ListView.selection property to control the selection. ListView.selection property is of WinJS.UI.ISelection type. You can call ListView.selection.set(-1) so as to clear the selection.

    #WinJS.UI.ISelection interface
    http://msdn.microsoft.com/en-us/library/windows/apps/hh872204.aspx

     


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

    • Proposed as answer by Can Bilgin Tuesday, May 7, 2013 8:48 AM
    • Marked as answer by ZachAtttack Tuesday, May 7, 2013 6:34 PM
    Monday, May 6, 2013 1:46 AM
    Moderator