how to build hierarchical data template with treeview wpf mvvm pattern

4 posts, 2 answers
  1. Kumar
    Kumar avatar
    5 posts
    Member since:
    Sep 2012

    Posted 24 Sep 2012 Link to this post

    Do we need to have a HierarchicalDataTemplate for each level fot Telerik RadtreeView.

    -Departments

    -EmployeeA
    • aaa
    • bbb
    • ccc

    -Employee B

    • aaa
    • bbb

    for the above do I need to have two HierarchicalDataTemplates ?

    Where Department is the Parent and employeeA, B are childs

  2. Answer
    Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 26 Sep 2012 Link to this post

    Hi Kumar,

    HierarchicalDataTemplate is used when a node of a collection has its own children which are also wrapped in a collection. In order to relate each child to a DataTemplate, the ItemTemplate and ItemsSource properties of the HierarchicalDataTemplate must be used.
     
    In your case a DataTemplate can be used to display the children of EmployeeA and EmployeeB. A HierarchicalDataTemplate is needed to display all employees in one department and one more HierarchicalDataTemplate to display all departments in the collection.

    For better understanding and your convenience I have attached a SampleProject which you may go through.

    For further information you may follow the links bellow:
    - How to bind to hierarchical data
    - Binding data using ItemTemplateSelector

    Please let me know if my answer satisfy your needs.

    All the best,
    TeamX2_Pavel
    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Kumar
    Kumar avatar
    5 posts
    Member since:
    Sep 2012

    Posted 27 Sep 2012 Link to this post

    Thanks, am able to build the Radtreeview with child items, I used the load on demand event to load the child items and it works for fine.
    The problem here is for every child item there is expand sign but there is a point there are no child items for a parent in that case for the child items I don't want show the expand sign. How can I achieve this ? 
  5. Answer
    Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1182 posts

    Posted 02 Oct 2012 Link to this post

    Hello Kumar,

    You can set the IsLoadOnDemandEnabled property to each RadTreeViewItem separately. It's best to use the RadTreeView.ItemPrepared event handler to set the IsLoadOnDemandEnabled property to False for those items that won't display any children.

    You may read more about this approach in our Help Article or take a look through our Demo Project.

    Kind regards,
    TeamX2_Pavel
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top