I've searched the complete forum but can't find an answer.
I'm trying to make a hierarchical treeview with domaincontext.
De database exists of 3 tables (Day, Team and Task).
The problem I have is because of the relationship in my database:
DAY 0..1---->* Task *<---- 1 Team
I would like to get the Day as parentnode. The next nodes should be the Teams and the last node are the Tasks.
8 Answers, 1 is accepted
Having this scenario you should perform a bit of data transformation by your own.
The most straight forward approach is to create collection of Day objects. Each Day object should have collection of teams. And each team a collection of tasks. You could easily process the "Task" table and fill each Day's team collection. Unfortunately this should be done by you in order to transform your custom data scheme to something more general that the TreeView can handle.
Hope this helps. Let me know if you need more info about the suggested solution or it is not applicable to your case.
the Telerik team
thanks for your reply.
I've made two views. 1 view contains a DateID and TeamID(vw_days). The second view contains TeamID, DateId and TaskID (vw_Teams).
The vw_Teams is linked to the task table. So I've tried to create the following scenario:
vw_Day 0..1---->* vw_Teams 1----->* Tasks
I can't get it work with the entity data model. I've found on the internet this isn't possible.
Maybe i didn't understand you right so maybe you could give me some more information?
If it's easier I could also drop the daytable from the database. I've got twelve fixed days. Under every day the Team with the corresponding tasks for that day should be displayed.
Task: 01-01-2011 task 1
Task: 01-01-2011 task 2
Task: 02-01-2011 task 1
Task: 02-01-2011 task 2
Thanks for your help!
By changing the datamodel i've run into some other problems so i'm back to the initial problem.
Could you give me some more information on the suggested solution?
Thanx in advance,
I am sending you a sample project demonstrating how to transform many-to-many relationship into parent-child relationship using WCF Ria Services and Load On demand. The trick is that I am setting the ItemsSource collection of the expanded RadTreeViewItem in the LoadOnDemand handler. I have Categories ---> Product <----Suppliers relationship from the standard NorthWind database. The Products table holds the CategoryID and SupplierID. The solution demonstrates how to show Categories on a root level and Suppliers for the particular category in the second level. You should be able to get the idea how to create the third level using LOD feature again. Please examine it and let me know if it fits in your scenario.
the Telerik team
thank you very much, this is exactly what I was looking for.
I understand your solution, but i have one problem.
Under the Category node all the suppliers are shown (which is perfect!)
When I click on a supplier I want to show all the products for that particular Category AND Supplier so I've the following code:
private void treeView_LoadOnDemand(object sender, Telerik.Windows.RadRoutedEventArgs e)
RadTreeViewItem selectedContainer = e.OriginalSource as RadTreeViewItem;
Category selected = selectedContainer.Item as Category;
Supplier selected2 = selectedContainer.Item as Supplier;
if (selected != null)
var querySuppliers = service.GetSuppliersQuery();
var queryProducts = service.GetProductsQuery();
selectedContainer.ItemsSource = service.Suppliers.Where(x => x.Products.Count(y => y.CategoryID == selected.CategoryID) != 0);
else if (selected2 != null)
var querySuppliers2 = service.GetSuppliersQuery();
var queryProducts2 = service.GetProductsQuery();
var queryCategories2 = service.GetCategoriesQuery();
selectedContainer.ItemsSource = service.Products.Where(x => x.SupplierID == selected2.SupplierID).Where(y => y.CategoryID == selected.CategoryID);
selectedContainer.IsLoadingOnDemand = false;
If I use this code i get an object reference exception on the selected.CategoryID.
How can I also select the CategoryID for the products beneath the Category and suppliers??
In your case when LoadOnDemand fires, you had clicked category or supplier not both. So you can get the category for the clicked supplier by the ParentItem.Item property of the RadTreeViewitem.
the Telerik team
thanks for you reply.
I've tried this solution before but without the wanted result.
It seems that i've made a mistake with my hierarchical datatemplate in the treeview.
With your sample project I found the solution i wanted so thank you very much for your help!