1

how can i bind SelectedItems of a ListView? My ListView has multipleSelection attribute and I'm using CollectionView for its contents..

I've heard about Attached property and I tried implementing this with the one I found here: Sync SelectedItems in a muliselect listbox with a collection in ViewModel

I can multiple select the items by clicking rows but I can't use the Shift keyboard for multi-selecting many rows instantly... Also, when I filter my collection and refresh it, my selection are all deselected after the refresh..

How can I make it so that whenever my CollectionView refreshes, the previously selecteditems are still selected after the refresh...?

Can someone also help me how to manipulate logically the selected items through my viewmodel?

Community
  • 1
  • 1
izzra
  • 55
  • 3
  • 7

2 Answers2

1

May be you should add the IsSelected property to the ListViewItem's view model.

Y.Yanavichus
  • 2,387
  • 1
  • 21
  • 34
  • +1 This is what I usually do - add an `IsSelected` property to the object and bind it in the `ListViewItem` Style – Rachel Jan 25 '12 at 19:54
  • 1
    How can this be the "True WPF way"? It is putting a property that is purely for the view into the model? I guess if you are willing to convert from your object to a custom ViewModel only object, then you can keep it in the view model. But still, something that should be View only is getting out. – Vaccano Dec 12 '13 at 18:05
  • @Vaccano: I guess you are confusing Model and ViewModel. I suggested to put a property from a View to the ViewModel. Then you can add calculated property to ViewModel: SelectedItems. – Y.Yanavichus Dec 12 '13 at 18:18
0

You will have to use your own code to keep the selected items after a refresh. Maybe make a copy of your collection before the refresh and afterwards a simple for to check all the checked items in your current collection.

Change your selectection mode to extended for your listbox for the shift key to work.

As for manipulating logically the selected items, you will have to give a lot more info on what exactly you want done.

TBohnen.jnr
  • 5,117
  • 1
  • 19
  • 26