32

I'm having trouble in multiple items selection in an ListBox.

I've tried deriving new control from Selector and writing ListBox helper class which did not work (as expected).

The issue with Selector class is, it does not expose SelectedItems and it's hell to bind the property and manipulate it with selection changed event.

The issue with ListBox Helper class is, I'm getting the required data on multiple selection but it never hits the bound property.

Does anybody know a better way to implement multiselect listbox?

Thanks in advance...

Pieniadz
  • 653
  • 3
  • 9
  • 22
ni3a
  • 461
  • 2
  • 7
  • 10
  • P.S. Seems, I've provided less info. I'm using MVVM where SelectedItems is not accessible without readonly property binding, which is again an overhead for me. :) – ni3a Jun 20 '11 at 16:32

1 Answers1

73

The ListBox has multiple selection already implemented. Just change SelectionMode property to Multiple or Extened.

You can use SelectedItems property to get all the selected items afterwards.

Adrian Fâciu
  • 12,414
  • 3
  • 53
  • 68
  • 3
    @AdrianFaciu But it is not possible to set SelectedItems from the viewmodel? – Vitalii Vasylenko May 02 '13 at 15:50
  • 4
    @Vitalii Vasylenko Yes you can, but not straight forward. Have a look here for an example: http://stackoverflow.com/questions/11142976/how-to-support-listbox-selecteditems-binding-with-mvvm-in-a-navigable-applicatio – Adrian Fâciu May 08 '13 at 11:18