IEditableCollectionView & Sorting

5 posts, 0 answers
  1. Chris
    Chris avatar
    30 posts
    Member since:
    Oct 2010

    Posted 09 Apr 2012 Link to this post

    We are currently evaluating RadTreeView and we have an MVVM sorting scenario that is not working correctly.  Note that everything was working fine with another treeview that was just a standard ItemsControl with some multi-selection capabilities added.  

    Certain nodes in the tree are sorted by adding SortDescriptions to ListCollectionView and the sorting works fine when items are added or removed.

    The problem I'm having is with updating the sort order in reaction to changes made to the backing viewmodel objects.  I am trying to leverage IEditableCollectionView as described here:  http://drwpf.com/blog/category/collections/.

    In the code below, treeViewItem is the RadTreeViewItem that is attached to the modified object:

    IEditableCollectionView ev = treeViewItem.ParentTreeView.Items;

    if (ev != null)
    {
        // this forces the parent to re-sort in response to the sort field changing
        ev.EditItem(treeViewItem.DataContext);
        ev.CommitEdit();
    }

    The code compiles & runs, but the tree is not updated with the new sort order.

    If I instead call refresh, the treeview is updated with the correct sort order:

    treeViewItem.ParentTreeView.Items.Refresh();

    However, the tree can have hundreds of items in it and I really don't want to call Refresh for performance reasons.  

    Is there a way to get this scenario working?  This is the one thing preventing us from being able to use RadTreeView instead of the TreeView we were using before.

  2. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 10 Apr 2012 Link to this post

    Hi Chris,

    I've created a sample project to simulate the issue in a simple scenario. I couldn't manage to simulate the issue. Could you please try to modify the project in order to simulate it, or provide us with steps to reproduce?

    I'm looking forward for your post.

    Kind regards,
    Hristo
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Chris
    Chris avatar
    30 posts
    Member since:
    Oct 2010

    Posted 12 Apr 2012 Link to this post

    Thanks for the sample - it helped me figure out where the problem is.

    It looks like the dynamic re-sorting only works at the root node, so if I have the following hierarchy:

    - Parent1
        - Child1
        - Child2
        - Child3
    - Parent2
        - Child4
        - Child5
        - Child6


    If I rename "Parent2" to "A", the parent nodes re-sort as they do in the sample you gave me.
    If I rename "Child3" to "A", the child nodes do not sort.

     Again, this scenario works fine with a standard .NET control.
  5. Chris
    Chris avatar
    30 posts
    Member since:
    Oct 2010

    Posted 13 Apr 2012 Link to this post

    Ok, I have the solution.

    In the case of nodes below the root level, I just needed to get a hold of the parent item's Items collection and call EditItem/CommitEdit on that.

  6. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 17 Apr 2012 Link to this post

    Hi Chris,

    We're glad to hear that you've resolved the issue.

    However, if you need more information or assistance while using our controls, please let us know.

    All the best,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
UI for WPF is Visual Studio 2017 Ready