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

How to go through all RadTreeViewItems?

6 Answers 303 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Yuri M
Top achievements
Rank 1
Yuri M asked on 27 May 2010, 07:30 PM
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

6 Answers, 1 is accepted

Sort by
0
Yuri M
Top achievements
Rank 1
answered on 01 Jun 2010, 11:11 PM

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.
0
Valentin.Stoychev
Telerik team
answered on 02 Jun 2010, 07:31 AM
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.
0
Yuri M
Top achievements
Rank 1
answered on 02 Jun 2010, 03:51 PM
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.
0
Accepted
Tina Stancheva
Telerik team
answered on 08 Jun 2010, 04:04 PM
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.
0
Yuri M
Top achievements
Rank 1
answered on 10 Jun 2010, 07:19 PM
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.
0
Valentin.Stoychev
Telerik team
answered on 15 Jun 2010, 08:00 AM
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.
Tags
TreeView
Asked by
Yuri M
Top achievements
Rank 1
Answers by
Yuri M
Top achievements
Rank 1
Valentin.Stoychev
Telerik team
Tina Stancheva
Telerik team
Share this question
or