WPF - Extend ListView with checkable AND selectable ListViewItems

Posted by Marks on Stack Overflow See other posts from Stack Overflow or by Marks
Published on 2010-05-05T16:04:11Z Indexed on 2010/05/05 16:08 UTC
Read the original article Hit count: 224

Filed under:
|
|
|

Hi there. I already read many examples on extending ListViews with checkboxes bound with IsSelected. But I want something more.

I want a seperation between the checked and selected state, so i get a ListBox that has a single selected item, but can have multiple checked items. Unfortunately ListViewItem does not have a property for checked and I dont see a possibility to get the ListView to work with a custom CheckableListViewItem.

Of course i could use a List of objects with a checked property as ItemSource, but I dont think thats a good way to go. Checked or not is a matter of the list or item-container, not of the object listed in it. Beside that I dont want all my classes like user, role, group to have counterparts like checkableUser, checkableRole and checkableGroup.

The behaviour i want can be easyly accomblished for the UI with a

<DataTemplate x:Key="CheckBoxCell">
   <StackPanel Orientation="Horizontal">
      <CheckBox />
   </StackPanel>
</DataTemplate>

and a

<GridViewColumn CellTemplate="{StaticResource CheckBoxCell}" Width="30"/>

But without a binding on the checkbox i cant check if it is checked or not.

Is there any way to accomplish something like that? The perfect solution for me would be to have listView1.SelectedItem, listView1.CheckedItems and maybe a listView1.UncheckedItems and of course listView1.CheckItem and listView1.UncheckItem.

Thanks for any help.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about listview