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

How to set ItemEdit Template in treeview?

1 Answer 8 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Rahul
Top achievements
Rank 1
Rahul asked on 10 Nov 2020, 10:58 AM

I am not able to set ItemEdit template in the treeview!

My template name is : CarEditTemplates

Basically what is the values to be set in the Dispalymemeberpath="" & ITemSourcePath=""?

 <StackLayout Grid.Row="1" BackgroundColor="White" Margin="5">
                  <telerikDataControls:RadTreeView  x:Name="treeView" ItemsSource="{Binding MobileEditTemplates}">
                       <telerikDataControls:TreeViewDescriptor DisplayMemberPath="{Binding Name}" ItemsSourcePath=" " TargetType="{x:Type local:MobileEditTemplates}">
                            <telerikDataControls:TreeViewDescriptor.ItemTemplate>
                                <DataTemplate>
                                    <Grid Margin="2">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="20" />
                                            <ColumnDefinition Width="*" />
                                        </Grid.ColumnDefinitions>
                                        <telerikTreeView:ExpandCollapseIndicator FontSize="Medium" WidthRequest="10" Margin="15,0" VerticalTextAlignment="Center" />  
                                        <telerikTreeView:ItemText Grid.Column="1" FontAttributes="Bold" FontSize="Small" Text="{Binding Name}" TextColor="Gray" VerticalTextAlignment="Center"/>
                                    </Grid>
                                 </DataTemplate>
                            </telerikDataControls:TreeViewDescriptor.ItemTemplate>
                    </telerikDataControls:TreeViewDescriptor>
                    <telerikDataControls:TreeViewDescriptor DisplayMemberPath="Name"
                                            TargetType="{x:Type local:SymbolItem}" />
</telerikDataControls:RadTreeView>
                </StackLayout>

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 10 Nov 2020, 03:04 PM

Hi Rahul,

DisplayMemberPath and ItemsSourcePath should be set to properties of the data item the TreeViewDescriptor defines.  The DisplatMemberPath marks the name of the property that should be displayed in case no ItemTemplate is defined, ItemsSourcePath marks the name of the list property which contains the subitems ( as the TreeView visualizes hierarchical data).

For example, let's take a look at the first TreeViewDescriptor in the provided snippet which describes the MobileEditTemplates data item.  If you'd like the items of type MobileEditTemplates  to have subitems, you would to define a collection of these items:

public class MobileEditTemplates 
{ 
    public MobileEditTemplates(string name)
    {
        this.Name = name;
        this.Children = new ObservableCollection<MobileEditTemplates>();
    }

    public string Name { get; set; }
    public IList<MobileEditTemplates> Children { get; set; }
}

Subitems can be of the same type as their parent or a different type. If they're of a different type, you should add a TreeViewDescriptor for that type as well.

Basically, you can set Children and Name properties of the MobileEditTemplates to the ItemsSourcePath and DisplayMemberPath properties , respectively.

You can take a look at our Getting Started and Item Template examples for a complete implementation.

I hope I was of help. Let me know if any additional questions pop up.

Regards,
Yana
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
TreeView
Asked by
Rahul
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or