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

how to build hierarchical data template with treeview wpf mvvm pattern

3 Answers 370 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Kumar
Top achievements
Rank 1
Kumar asked on 25 Sep 2012, 03:37 AM

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

3 Answers, 1 is accepted

Sort by
0
Accepted
Pavel R. Pavlov
Telerik team
answered on 26 Sep 2012, 02:09 PM
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.

0
Kumar
Top achievements
Rank 1
answered on 28 Sep 2012, 04:48 AM
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 ? 
0
Accepted
Pavel R. Pavlov
Telerik team
answered on 02 Oct 2012, 02:51 PM
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.

Tags
TreeView
Asked by
Kumar
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Kumar
Top achievements
Rank 1
Share this question
or