This is a migrated thread and some comments may be shown as answers.
Hierarchical Treeview issue
8 Answers 56 Views
This is a migrated thread and some comments may be shown as answers.
Albert
Top achievements
Rank 1
Albert asked on 10 Jan 2011, 01:55 AM
Dear Telerik Team,

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

Sort by
0
Accepted
Hristo
Telerik team
answered on 10 Jan 2011, 10:29 AM
Hello Albert,

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.

All the best,
Hristo
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Albert
Top achievements
Rank 1
answered on 10 Jan 2011, 12:19 PM
Hi Hristo,

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.
Example:

Date:01-01-2011
     Team: 1
Task: 01-01-2011 task 1
      Team: 2
        Task: 01-01-2011 task 2
Date:02-01-2011
     Team: 1
Task: 02-01-2011 task 1
      Team: 2
        Task: 02-01-2011 task 2

0
Albert
Top achievements
Rank 1
answered on 10 Jan 2011, 01:03 PM
I've solved the problem by changing my datamodel.
Thanks for your help!
0
Albert
Top achievements
Rank 1
answered on 26 Jan 2011, 08:50 PM
Hi Hristo,

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,
Albert.
0
Petar Mladenov
Telerik team
answered on 28 Jan 2011, 04:31 PM
Hello Albert,

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.

Best wishes,
Petar Mladenov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Albert
Top achievements
Rank 1
answered on 29 Jan 2011, 03:07 PM
Hi Petar,

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);
                service.Load(querySuppliers);
                service.Load(queryProducts);
            }

            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??
0
Accepted
Petar Mladenov
Telerik team
answered on 03 Feb 2011, 11:16 AM
Hello Albert,

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.

Kind regards,
Petar Mladenov
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Albert
Top achievements
Rank 1
answered on 06 Feb 2011, 01:22 PM
Hi Petar,

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!

Best wishes,
Albert.
Asked by
Albert
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Albert
Top achievements
Rank 1
Petar Mladenov
Telerik team
Share this question
or