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

Binding BizObj to RadTreeView

3 Answers 64 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jon Bergquist
Top achievements
Rank 1
Jon Bergquist asked on 20 Dec 2008, 05:32 AM
Hi.  I recently saw the blog on how to use the LoadOnDemand feature to bind WCF data to a Treeview but I cannot get the children to populate correctly.  Looking at the sample code it seems all you have to do is objects to the bound itemsource defined in the HierachicalDataTemplate.  Here is my xaml and code:

 

<telerikNavigation:RadTreeView x:Name="RadTree" IsLoadOnDemandEnabled="True" LoadOnDemand="RadTree_LoadOnDemand">

 

<telerikNavigation:RadTreeView.ItemTemplate>

 

<core:HierarchicalDataTemplate ItemsSource="{Binding ChildrenNodes}">

 

<TextBlock Text="{Binding Name}" Margin="5,0" />

 

</core:HierarchicalDataTemplate>

 

</telerikNavigation:RadTreeView.ItemTemplate>

 

</telerikNavigation:RadTreeView>

code behind:
//in the load method

ObservableCollection <TreeNode> Nodes = new ObservableCollection<TreeNode>();

//populate a bunch of node objects

 

RadTree.ItemsSource = Nodes;

 

 

 

private

void RadTree_LoadOnDemand(object sender, Telerik.Windows.RadRoutedEventArgs e)

 

 

{

 

RadTreeViewItem item = e.OriginalSource as RadTreeViewItem;

 

TreeNode node = item.Item as TreeNode;

 

TreeNode childNode = new TreeNode();

childNode.NodeId = 55;

childNode.Name =

"I'm a Child!";

 

 

node.ChildrenNodes =

new ObservableCollection<TreeNode>();

 

 

 

 

node.ChildrenNodes.Add(childNode);

}

and simple biz obj
public class TreeNode : INotifyPropertyChanged  

 

 

{

 

 

private int nodeId;

 

private string name;

 

 

 

public event PropertyChangedEventHandler PropertyChanged; 

 

 

 

private ObservableCollection<TreeNode> _children;
public ObservableCollection<TreeNode> ChildrenNodes...

 

 

 

 

public int NodeId...

 

 

 

public string Name...

 

 

 

private void OnPropertyChanged(string p)...

 

 

 

}

I've tried to make it as simple as possible but I can only populate the root nodes, not the ChildrenNodes.  I think the problem is somewhere in my LoadOnDemand event handler.

Thanks

 

 

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Valentin.Stoychev
Telerik team
answered on 22 Dec 2008, 03:27 PM
Hello Jon Bergquist,

I'll wait for your project. I already wrote in the other thread that you have opened.

Sincerely yours,
Valentin.Stoychev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Amruta
Top achievements
Rank 1
answered on 19 Mar 2010, 02:35 PM
Hi,

I am facing a problem while refreshing the treeview after calling wcf service on OnLoadDemand event and refreshing the list which is used to bind the treeview.

This is the scenario -
I have a class say "TreeItem". It has its own properties. I create a list of items of this type at runtime and bind this list to the treeview using ItemSource of the treeview.

I am also using LoadOnDemand for some of the nodes of the treeview as it can have a large number of child nodes.

I use LoadOnDemand to fetch the results. I give asynch call to my WCF service and gets a list of items. I add these items in the child list of the node. But i am not able to refresh the treeview at this time. I need to make the itemsource null and rebind it again which causes the treeview to collapse and then i am able to get the newly created nodes.

How can i refresh the treeview after getting results from wcf service without making the itemsource null?

Thanks & Regards,
Amruta.
0
Tina Stancheva
Telerik team
answered on 25 Mar 2010, 10:28 AM
Hi Amruta,

Please accept my apologies for the late response.

The problem you're facing could be caused by the type of your ItemsSource collection (in this case the list of items you're creating at runtime). If you're using a List collection, the changes you make to the RadTreeView ItemsSource won't affect the original business object and vice versa.

If this is the case, then you should use ObservableCollection instead of List.

Can you please give it a try and let us know if it works for you. if not, can you please send us a simple project reproducing your issue, so that we can further investigate it.

Best wishes,
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.
Tags
TreeView
Asked by
Jon Bergquist
Top achievements
Rank 1
Answers by
Valentin.Stoychev
Telerik team
Amruta
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or