Retrieving RadTreeViewItem using code

4 posts, 0 answers
  1. Indu VS
    Indu VS avatar
    6 posts
    Member since:
    Aug 2009

    Posted 21 Aug 2009 Link to this post

    I want to retrieve RadTreeViewItems from a RadTreeView. i tried the below code in a method,but it is not working.
    here 'controlsTree' is the radtreeview and 'item' is the datacontext of that node.

    RadTreeViewItem itemss = controlsTree.ItemContainerGenerator.ContainerFromIndex(1) as RadTreeViewItem;
    RadTreeViewItem itemss = controlsTree.ItemContainerGenerator.ContainerFromItem(item) as RadTreeViewItem;

    Is there any other method to do this?
  2. Tihomir Petkov
    Tihomir Petkov avatar
    576 posts

    Posted 21 Aug 2009 Link to this post

    Hello Indu,

    The methods you are using would work only for the immediate children of the treeview. So, if you try to get a treeview item that is not at the top-most level of items using the code you provided in your post,
    you will not be able to get it because the ItemContainerGenerator is hierarchly aware. Meaning that the TreeView.ItemContainerGenerator will only know direct children of the TreeView. and the TreeViewItem.ItemContainerGenerator will only knows it's own direct children.
    So essentially a TreeView has as many ItemContainerGenerators as it has TreeViewItems+1. And again, each of these ItemContainerGenerators only knows about the children of the instance it belongs to. So, to be able to get the item you need, you should use the ItemContainerGenerator of the item's parent - this is either the TreeVIew itself if the item is at the root level, or another treeview item.

    you may find these two links helpful:

    Let me know if you have more questions.

    Tihomir Petkov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. StrandedPirate
    StrandedPirate avatar
    32 posts
    Member since:
    Nov 2007

    Posted 22 May 2010 Link to this post

    Being new to silverlight and this wacked API I had the same issue. I finally found the RadTreeView.ContainerFromItemRecursive() method that allows you to do this. Here is some sample code for reference where I am recursively iterating over the Items collection to find one that matches a string and using the ContainerFromItemRecursive method to find the UI element that represents the item. This is for Q1 2010 version.



    private void Button_Click(object sender, System.Windows.RoutedEventArgs e)







    private void FindItem(ItemCollection collection)





    foreach (tbl_Path path in collection)





    RadTreeViewItem item = FolderTreeView.ContainerFromItemRecursive(path) as RadTreeViewItem;




    if (path.Name().ToLowerInvariant().StartsWith(FindTextbox.Text.ToLowerInvariant()))



    item.IsSelected =











    else if (item.HasItems)







  4. Bobi
    Bobi avatar
    513 posts

    Posted 26 May 2010 Link to this post

    Hi Joey,

    Thank you for the feedback. You can find some more help  here:

    Please let us know if you have any other questions or need some more help.

    Best wishes,
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top