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

Virtualization, Selection and BringPathIntoView - How ?

5 Answers 134 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Bernd
Top achievements
Rank 1
Bernd asked on 29 Aug 2012, 04:10 PM
Hello,
we're evaluating the RadTreeView in order to replace the Silverlight Toolkit TreeView. The Reason is that we have trees where nodes can have >1000 children and we need Virtualization.

One Feature in our application is a search inside the tree. We do this in our ViewModel by exposing a Property "SelectedItem" and bind this to the TreeView via TwoWay binding. The ViewModel sets the SeletedItem - Property, so it's selected in the tree:

<telerik:RadTreeView IsVirtualizing="True" ItemsSource="{Binding Portfolios}"
    SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
    BringIntoViewMode="HeaderAndItems"
    telerik:TextSearch.TextPath="Name">
    <telerik:RadTreeView.ItemTemplate>
        <telerik:HierarchicalDataTemplate ItemsSource="{Binding Portfolios}">
...
        </telerik:HierarchicalDataTemplate>
    </telerik:RadTreeView.ItemTemplate>
</telerik:RadTreeView>

private void JumpInTree(object obj)
{
    var item = mySearchList.GetNextSearchItem(...) as BaseViewModel;
    if (item != null)
        SelectedItem = item;
}

Selection works fine but the tree does not expand and scroll to the selected item. I've tried to derive a TreeView from RadTreeView, override the OnSelectionChanged() and bring the selected item into the view there. Problem is due to virtualization that the TreeViewItems are not generated when they're not visible, so ContainerFromItemRecursive() does not work and many other attempts also:
public class BindableTreeViewNew : RadTreeView
{
    protected override void OnSelectionChanged(Telerik.Windows.Controls.SelectionChangedEventArgs e)
    {
        base.OnSelectionChanged(e);
 
        // the correct selected Item
        var item = SelectedItem;
         
        // can't rely on this
        var selectedContainer = SelectedContainer;
 
        // does not work because item was not visible yet:
        var selectedContainer2 = ContainerFromItemRecursive(SelectedItem);
 
        // this works but how to get the path of SelectedItem?
        BringPathIntoView(@"Root\XYZ\ABC");
    }
}

BringPathIntoView() works with a hardcoded Path but now the problem is: How to get the Path of the selected item?

When searching your forum, I've found another approach using ContainerBinding described here:
http://www.telerik.com/help/silverlight/radtreeview-how-to-bind-hierarchical-data-use-containerbindingcollection.html 
But this approach would force us to put UI or user control specific properties into our ViewModels which is not an option, Also the objects could live in two different trees on the same view so we would have to introduce "IsSelected" and "IsExpanded" properties for tree 1 and another property set for tree 2, otherwise selection in tree 1 would cause side effects on tree 2.

Can anybody help me to find a solution for this?

Thanks in advcance,
  Bernd




5 Answers, 1 is accepted

Sort by
0
Accepted
Petar Mladenov
Telerik team
answered on 30 Aug 2012, 06:02 AM
Hi Bernd,

 We hope this help article will help you set up your project properly.

Regards,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Bernd
Top achievements
Rank 1
answered on 30 Aug 2012, 09:49 AM
Hi Petar,

Thank you for your fast response. Building up the path inside the ViewModel did the trick.

I was hoping that we could get the path of the selected item somehow in a generic/automatic way, because the given solution forces us to implement control specific logic in our ViewModels (=building the path, keeping it up to date when rearranging).
But as we use this search feature only in 2 places of our application, this is OK for us.

Best regards,
  Bernd
0
Gopala
Top achievements
Rank 1
answered on 01 Apr 2013, 05:33 PM
I want to do same thing. I added Path to my collection item. I can get path for each treeview item. But I cannot find BringPathIntoView for my RadTreeView. Am I missing something.
0
Tina Stancheva
Telerik team
answered on 03 Apr 2013, 12:41 PM
Hi Gopala,

We've posted a reply in the other forum thread you started and it will best to keep the communication there.

Regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Gopala
Top achievements
Rank 1
answered on 03 Apr 2013, 11:47 PM
Ok...
Tags
TreeView
Asked by
Bernd
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Bernd
Top achievements
Rank 1
Gopala
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or