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

Expand and Search in Code Behind

7 Answers 210 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Prash
Top achievements
Rank 1
Prash asked on 27 Mar 2009, 09:17 AM
Hello,

I am facing a problem on the Treeview,
The scenario is this that the I am trying to search an item(Business Object), with the help of  trvNetworkView.ContainerFromItemRecursive(obj)
but the tree is OnDemand Load enabled so I do it in the code behind and then try to expand the treeview so that i can search the given item in treeview, in the very next line.

trvNetworkView.BringIntoView();
trvNetwork.LoadNode(trvNetworkView.Items[0] );
trvNetwork.LoadNode(trvNetworkView.Items[0]).IsExpanded = true;
DObject parentObject = GetObject(selObj.ParentObjectID);
//LoadNode performs the LoadOnDemand
trvNetwork.LoadNode(parentObject);
RadTreeViewItem treeItem = ((RadTreeViewItem)trvNetworkView.ContainerFromItemRecursive(parentObject));
treeItem.IsSelected = true;
treeItem.IsExpanded = true;
treeItem.BringIntoView();

foreach (DObject item in parentObject.Childrens)
 {
           if(item.ObjectID == selObj.ObjectID)
             {
                      itemFound = true;
                    ((RadTreeViewItem)trvNetworkView.ContainerFromItemRecursive(item)).IsSelected = true;
                       break;
               }
   }


but in the Foreach loop i always get the ((RadTreeViewItem)trvNetworkView.ContainerFromItemRecursive(item)) as null.

Can you please help

7 Answers, 1 is accepted

Sort by
0
Bobi
Telerik team
answered on 30 Mar 2009, 12:00 PM
Hello Prash,
 
I am attaching a sample project demonstrating how to get the item you want without first calling LoadOnDemand.

I hope that this will help you.

All the best,
Boryana
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Prash
Top achievements
Rank 1
answered on 31 Mar 2009, 11:46 AM
Hello ,
the sample that you prepared was helpful, but you have created the Items of the treeview on the design time, and the scenario in our case is that the items are generated at run time with the help of Load on demand. The  problem arises when we try of fetch the items on runtime, it calls the onloadDemand but since it is not expanded we are not getting the item by the ((RadTreeViewItem)trvNetworkView.ContainerFromItemRecursive(parentObject)); call.
as a result it always return null.

The root node itself is fetched bythe OnDemandLoad, and when we expand the root node the successive calls for onDemandload goes.

Any code for the same will be helpful.



0
Bobi
Telerik team
answered on 03 Apr 2009, 09:50 AM
Hello Prash,

I attached a sample project which demonstrates how to use LoadOnDemand as well as how to get an instance of the desired item.

I hope that this will help you.

Kind regards,
Boryana
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Prash
Top achievements
Rank 1
answered on 06 Apr 2009, 06:52 AM
Hello,
I saved the Project and unzipped it but when I try to open it it gives me following error.

The project file cannot be opened.
The project type is not supported by this installation.

Please look into this
Thanks and regards
0
Bobi
Telerik team
answered on 06 Apr 2009, 11:10 AM
Hi Prash,

Sorry for this inconvenience - I sent you a Silverlight version of the project. Please find attached the correct  WPF project.

Sincerely yours,
Boryana
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Prash
Top achievements
Rank 1
answered on 20 Apr 2009, 02:42 PM
Hello Boryana,

The sample you sent was really helpful. I am facing a problem where I am supposed to select the Item from the tree in the code behind.
I am writing the code for selection but the I am not able to select it as it is not generated, i.e the treeview has not come into view yet. I am getting the error In Containerfromgenerator, it is because the item is still in generating status.

Can you help? any code will be helpful.



0
Bobi
Telerik team
answered on 21 Apr 2009, 01:09 PM
Hi Prash,

I am not quite sure what exactly you are trying to do but in general LoadOnDemand is fired only when an item has no children. Please, take a look at the following discussions:

http://www.telerik.com/community/forums/silverlight/treeview/radtreeviewitem-expand-and-select.aspx
http://www.telerik.com/community/forums/silverlight/treeview/select-a-node-from-code-behind.aspx

You can also expand items using the ItemPrepared event as shown in the second example.

If any of the above articles does not help, please make a small project in which you isolate your issue and send it to us so that we can take a look and fix it.

Kind regards,
Boryana
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.
Tags
TreeView
Asked by
Prash
Top achievements
Rank 1
Answers by
Bobi
Telerik team
Prash
Top achievements
Rank 1
Share this question
or