coder
coder

Reputation: 4283

How to deselect items in listview (bound to List<myObject>) programmatically in Windows Phone 8.1

It's Windows Phone 8.1 Universal.

I need to be able to select and deselect items in the listview. I can't select/deselect a single item programmatically, but I can select all items in the listView with this method:

listView.SelectAll();

It would make sense to expect the exact opposite method built-in to deselect all, but there is none.

I can't use the following code because it's not bound to a list of ListItem object, but a custom object

        foreach (var item in listView.SelectedItems)
        {
            //item.IsSelected isn't available because it's a custom object
        }

How do I deselect all items in the listview?

Upvotes: 0

Views: 139

Answers (2)

Diomedes Domínguez
Diomedes Domínguez

Reputation: 1101

The other way is listiew.SelectedIndex = -1;

Upvotes: 0

coder
coder

Reputation: 4283

If figured it. The following code deselects all items in the listView:

listView.SelectedItems.Clear();

Upvotes: 1

Related Questions