This is a migrated thread and some comments may be shown as answers.

IEditableCollectionView & Sorting

4 Answers 133 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 09 Apr 2012, 03:33 PM
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.

4 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 10 Apr 2012, 02:51 PM
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 >>

0
Chris
Top achievements
Rank 1
answered on 12 Apr 2012, 10:21 PM
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.
0
Chris
Top achievements
Rank 1
answered on 13 Apr 2012, 03:03 PM
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.

0
Tina Stancheva
Telerik team
answered on 17 Apr 2012, 11:57 AM
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 >>

Tags
TreeView
Asked by
Chris
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Chris
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or