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

Selecting hierarchical node

5 Answers 166 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ketaki
Top achievements
Rank 1
Ketaki asked on 17 Sep 2009, 01:37 PM
Hi,

I have a tree view where I have 'n' levels of hierarchy items which are getting filled programatically. The tree is not LoadOnDemand but getting loaded initially. But root node OR parent node is shown to the user though full tree is loaded in memory.  So user can click on it and expand. I have one functionality which redirects me to the tree with an item, and i want to select that particular item from the tree which can be at any level(n). I called ItemsTreeView.ExpandAll() function to expand the tree and then under ItemsTree_Expanded event I am searching an item in the treeview by calling 
ItemsTreeView.ContainerFromItemRecursive(SelectedItemFromSearch);
But this returns me Null.

Can you plese suggest me a way to select an item in the tree hierarchy using ItemContainer way? or may be if there is some other way for doing it? Please reply as soon as possible as this is an urgent issue needs to be fixed.

Thanks in advance
Ketaki

5 Answers, 1 is accepted

Sort by
0
Bobi
Telerik team
answered on 18 Sep 2009, 01:54 PM
Hi Ketaki,

Thank you for the interest on RadControls for Silverlight.

ItemsTreeView.ItemContainerGenerator.ContainerFromItem(...)

will return the item container only if it is an immediate child of the TreeView.
You can recursively search the containers by using the TreeView.ContainerFromItemRecursive(item) method.

You need to handle the Expanded event and then to continue with the recursive logic.
The reason for this is that when you set the IsExpanded to true (in your ocassion you set ExpandAll()) the Silverlight framework generates the children asynchronously.
Alternatively you can use GetItemByPath/ExpandItemByPath.

Hopefully this will help you.
If you still have any questions or difficulties implementing your logic please send us some sample code in order to fix it.

Kind regards,
Boryana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Nikhil
Top achievements
Rank 1
answered on 18 Sep 2009, 04:42 PM
Hi Tech

I am facing the same problem.
Can please provide me sample application. its will great help

Regards,
Nikhil


0
Bobi
Telerik team
answered on 23 Sep 2009, 06:25 AM
Hello Nikhil,

Please find attached a sample project that shows the usage of ExpandItemByPath/GetItemByPath.
You may find these two links helpful:

http://silverlight.net/forums/t/65277.aspx

http://msdn.microsoft.com/en-us/library/system.windows.controls.itemcontainergenerator.aspx

I hope that this will be helpful.

Best wishes,
Boryana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Shura111
Top achievements
Rank 1
answered on 11 Nov 2009, 01:17 PM
Try to call UpdateLayout after ExpandAll :

        tv.ExpandAll();  
        tv.UpdateLayout();  
        tv.CollapseAll();  
                  
        RadTreeViewItem it = tv.ContainerFromItemRecursive(MyDataRow);  
        for (RadTreeViewItem parIt = it.ParentItem; parIt != null; parIt = parIt.ParentItem)  
          parIt.IsExpanded = true;  
        it.IsSelected = true;  
        it.Focus();  
 
0
Ivan
Telerik team
answered on 17 Nov 2009, 12:00 PM
Hello Alexander,

Thank you for the supplied code.

Please preview the attached example. Where the tree is expanded and a specific item is selected. About the ExpandAll method - there is no guarantee that items below the first level will be expanded.

Once again thank you for the sample code.

Greetings,
Ivan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
TreeView
Asked by
Ketaki
Top achievements
Rank 1
Answers by
Bobi
Telerik team
Nikhil
Top achievements
Rank 1
Shura111
Top achievements
Rank 1
Ivan
Telerik team
Share this question
or