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

HierarchicalDataTemplate - Edit item template

1 Answer 119 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Justin Lee
Top achievements
Rank 1
Justin Lee asked on 25 Feb 2013, 06:08 PM

I have a collection of categories, and each category contains a list of items.  I'm binding it to a RadTreeView and want the tree to be editable by the user.  I successfully bound the collection to the tree, however I'm I can't figure out how to have one data template for the editing of category, and another for editing of an item (child).  (the hierarchy is only 2 deep)

How can I have separate data templates for Editing?

<UserControl.Resources>
      <DataTemplate x:Key="ChildItemTemplate">
         <TextBlock Text="{Binding ItemName, Mode=TwoWay}" FontSize="9" Width="130" />
     </DataTemplate>
     <DataTemplate x:Key="CategoryEditTemplate">
         <TextBox Text="{Binding CategoryName, Mode=TwoWay}" FontSize="9" Width="130" />
     </DataTemplate>
     <telerik:HierarchicalDataTemplate x:Key="TreeDataTemplate" ItemsSource="{Binding ChildItems}"
                          ItemTemplate="{StaticResource ChildItemTemplate}">
         <TextBlock Text="{Binding CategoryName}" FontSize="9" />
     </telerik:HierarchicalDataTemplate>
 </UserControl.Resources>
 
 <telerik:RadTreeView ItemsSource="{Binding Categories}"
              ItemTemplate="{StaticResource TreeDataTemplate}"
              ItemEditTemplate="{StaticResource CategoryEditTemplate}"  />

1 Answer, 1 is accepted

Sort by
0
Accepted
Pavel R. Pavlov
Telerik team
answered on 28 Feb 2013, 04:38 PM
Hi Justin,

In order to set different DataTemplates when you go in edit mode you can use the ItemEditTemplateSelector property of the RadTreeView control. Please keep in mind that when using this property you have to set the ItemEditTemplate property of the control to Null. For more information you can refer to this article. In the attached project I created an EditTemplateSelector class deriving from DataTemplateSelector and I overrode the SelectTemplate() method. Please take a look at the attached project and let me know if it works for you.

Regards,
Pavel R. Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

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