Search code examples
wpfinotifypropertychangeditemssourcecheckedlistbox

Edit collection in separated ListBoxes


I have source elements like this:

var collection = new ObservableCollection<SourceItems>(source);

source implements INotifyPropertyChanged

I need to edit and view this collection in CheckListBoxes (listBox with checkBoxes from WPFToolKit)with rules:

  • every CheckListBoxes must be sort by one of collection's field. Collection has order field for each CheckListBox. For example - ItemOrder.
  • visible elements in one listBox depend on checked items from other.

Every CheckListBox has itemsSource

checkListBox1.ItemsSource=collection;

So, if i check items in one listBox i must see only checked items in other. And every listBox must be sorted by one of source's field

  • listBox1 by field orderItem

  • listBox2 by field orderVisibleItem and so on.

User can move elements in each listBoxes and it must not affect ordering in other.

I tried create CollectionViewSource for every ListBox. But when I sort one, it sort each other.

Linq for filtering and sortnig don't work too, because changes not updating dynamicly.

Is there best way to create such functionality?


Solution

  • You should use CollectionViewSource. I'm guessing that you used CollectionViewSource.GetDefaultView(.. ) ? you should create two NEW views for the collection:

    CollectionViewSource cvs = new CollectionViewSource() { Source = TheCollection };