Virtualization, Selection and BringPathIntoView - How ?

6 posts, 1 answers
  1. Bernd
    Bernd avatar
    3 posts
    Member since:
    Sep 2012

    Posted 29 Aug 2012 Link to this post

    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




  2. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 30 Aug 2012 Link to this post

    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.

  3. DevCraft banner
  4. Bernd
    Bernd avatar
    3 posts
    Member since:
    Sep 2012

    Posted 30 Aug 2012 Link to this post

    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
  5. Gopala
    Gopala avatar
    28 posts
    Member since:
    Jul 2012

    Posted 01 Apr 2013 Link to this post

    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.
  6. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 03 Apr 2013 Link to this post

    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.

  7. Gopala
    Gopala avatar
    28 posts
    Member since:
    Jul 2012

    Posted 03 Apr 2013 Link to this post

    Ok...
Back to Top
DevCraft banner