Hierarchical Treeview issue

9 posts, 2 answers
  1. Albert
    Albert avatar
    13 posts
    Member since:
    Dec 2010

    Posted 09 Jan 2011 Link to this post

    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.

  2. Answer
    Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 10 Jan 2011 Link to this post

    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>>
  3. DevCraft banner
  4. Albert
    Albert avatar
    13 posts
    Member since:
    Dec 2010

    Posted 10 Jan 2011 Link to this post

    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

  5. Albert
    Albert avatar
    13 posts
    Member since:
    Dec 2010

    Posted 10 Jan 2011 Link to this post

    I've solved the problem by changing my datamodel.
    Thanks for your help!
  6. Albert
    Albert avatar
    13 posts
    Member since:
    Dec 2010

    Posted 26 Jan 2011 Link to this post

    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.
  7. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 28 Jan 2011 Link to this post

    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>>
  8. Albert
    Albert avatar
    13 posts
    Member since:
    Dec 2010

    Posted 29 Jan 2011 Link to this post

    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??
  9. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 03 Feb 2011 Link to this post

    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>>
  10. Albert
    Albert avatar
    13 posts
    Member since:
    Dec 2010

    Posted 06 Feb 2011 Link to this post

    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.
Back to Top
DevCraft banner