How to go through all RadTreeViewItems?

7 posts, 1 answers
  1. Yuri M
    Yuri M avatar
    4 posts
    Member since:
    May 2010

    Posted 27 May 2010 Link to this post

    We set TreeView's data source in a code behind using ItemsSource property. There is NO data load on demand, everything is already in source object. I can NOT go through all RadTreeViewItems (getting null) in a code behind, until user expands all them. This behaviour explained here: http://www.telerik.com/help/silverlight/radtreeview-how-to-iterate-through-treeviewitems.html, but no solution offered.
    None of the following methods work for me until user expands appropriate treeview node: ContainerFromIndexContainerFromItemContainerFromItemRecursive.  I also tried do as described here: http://www.telerik.com/community/forums/silverlight/treeview/radtreeviewitem-expand-and-select.aspx. It did not help.

    Could you please explain me how can I do this simplest elementary thing as move through all the RadTreeViewItems not making user expand every node in a tree?

    Thanks in advance

  2. Yuri M
    Yuri M avatar
    4 posts
    Member since:
    May 2010

    Posted 01 Jun 2010 Link to this post


    I tried to use the following work arounds:

    1) Expand the whole tree (EpandAll() method) as soon as it loaded, and then collapse it back. I faced other issue - performance. The tree with around 100 items and nesting level 6 would expand more that half a minute. I guess this is why Telerik development team actually does not provide the feature - performance suffers too much.

    2) As I realized first approach would not work for me, I tried other one - expand and collapse those items one-by-one that I actually need at this point of time in a program code (item.IsExpand = true). I faced other issue - items expanded asynchronously, so I can not expand all them inside one loop

    3) I modified 2nd approach - for each expanded item I added event handler on Expanded event where I supposed to continue the expansion until needed item is reached. That did not work for me either, coz it turned out Expanded handler does not guarantee you created children nodes inside the expanded item! It only signals about given node expanded, but it has nothing to do with direct children nodes that are still being created.

    I'm stuck at this point. I have no other idea how to run this simplest scenario.
  3. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 02 Jun 2010 Link to this post

    Hello Yuri M,

    Your observations are correct. You can't go thru the RadtreeViewItems because they just do not exist until they are part from the visual tree. This is how the Silverlight framework works and we can't do much about it.

    I wonder what is your scenario and why you need the item containers? Can't you just examine the collection that you are binding to the RadTreeView?

    Sincerely yours,
    Valentin.Stoychev
    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.
  4. Yuri M
    Yuri M avatar
    4 posts
    Member since:
    May 2010

    Posted 02 Jun 2010 Link to this post

    Hello Valentin,

    Thank you for response. My scenario is pretty simple - we have to provide user with a search functionality throughout the whole tree, so that he can enter any text in a textbox and press Find, in the case matching item (on any nesting level) should be found, selected and brought into view. I can find the item in the binding data source, but can not select it. To do that I have to get RadtreeViewItem first. Any idea?
    Thanks.
  5. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3299 posts

    Posted 08 Jun 2010 Link to this post

    Hello Yuri M,

    Please accept my apology for the delayed response.

    You can search through the RadTreeView ItemsSource collection and use GetItemByPath() method to get the RadTreeViewItem and select it afterwords.

    I attached a project illustrating this approach. Can you please take a look at it and let me know if it works for you.

    Greetings,
    Tina Stancheva
    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.
  6. Yuri M
    Yuri M avatar
    4 posts
    Member since:
    May 2010

    Posted 10 Jun 2010 Link to this post

    Yes, this work. Thank you.
    Though I can not still comprehend why methods ContainerFromIndexContainerFromItemContainerFromItemRecursive do not work this way while GetItemByPath does.

    And let me pay your attention to slightly weird behaviour of treeview when you invoke this GetItemByPath: it automatically expands the found node for user, so you do not need to invoke something like Expand, SelectedItem or BringIntoView for found node. It does visual changes though this methods supposed to return RadTreeViewItem object only. I'm Ok because that is what I need in my scenario, but in other scenario it might cause problem. You can easily check it.
  7. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 15 Jun 2010 Link to this post

    Hello Yuri M,

    thank you for letting us know - this behavior is by design.

    Regards,
    Valentin.Stoychev
    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