GGCO
GGCO

Reputation: 183

Listview Deselect C# Metro

How do I deselect all the values of a listview in a C# Metro application? I searched through the object browser and online and haven't been able to find anything. Thanks in advance!

Upvotes: 2

Views: 4491

Answers (2)

GGCO
GGCO

Reputation: 183

I found another way of doing what I want. I just have a list item that says "None" which is selected by default. When I select this item, the focus shifts off the other item previously selected. The solution given by Pako would work in a traditional Desktop/WPF environment, but apparently not a Metro one. Thanks for the help.

Upvotes: 1

Jarek
Jarek

Reputation: 3379

Have you tried clearing SelectedItems list? That's how it is normally done I think.

listView.SelectedItems.Clear();

Edit: To clarify some things, here's sample WPF application that clears selected items with no problem. Maybe Metro applications work somewhat different but I would assume that the logic should be the same.

<StackPanel>
    <ListView Name="listView">
        <ListViewItem>Item 1</ListViewItem>
        <ListViewItem>Item 2</ListViewItem>
        <ListViewItem>Item 3</ListViewItem>
        <ListViewItem>Item 4</ListViewItem>
    </ListView>
    <Button Click="Button_Click"
            Content="Clear selection" />
</StackPanel>

And here is the code beind:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        listView.SelectedItems.Clear();
    }

On button click list items are correctly deselected and no exception is being thrown.

Upvotes: 2

Related Questions