WPF - How to clear selection from ListView?
Asked Answered
I

1

9

This seems like it should be something fairly simple, but I just can't seem to get it to work.

I'd like to programatically clear the selection of the currently selected item in my ListView.

I've tried setting SelectedValue to null, setting SelectedItem to null, setting the SelectedIndex to -1, and even tried calling the UnselectAll method. In each and every case, SelectedItems.Count is still equal to one...

Any ideas?

Infecund answered 23/2, 2011 at 22:47 Comment(4)
Can we the XAML and some of the code?Season
possible duplicate of Clear wpf listbox selection using button in control template and no codebehindPerpetuate
@Drackir - Not a duplicate. I'm trying to use code behind and this has nothing to do with templates nor am I using ComboBoxes.Infecund
Sorry about the ComboBox. But I think the other solution stands whether or not you're using a codebehind.Perpetuate
P
26

You must put it into an empty collection

ListView.UnselectAll();

I have read the question again. If it does not work, then the problem may be with binding. Is the ListView bound??

Protract answered 23/2, 2011 at 22:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.