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

Limiting tree node depth

2 Answers 53 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 06 Jan 2011, 03:36 PM
I have 2 treeviews and both are bound to the same datasource.  In one tree, I want to show the full hierarchy of nodes, but in the other tree I just want to show the first 2 levels of nodes.  Is there anyway I can limit the number of levels a TreeView will display?  I would perfer to not have 2 separate datasources. (there are actions that update the datasource, and I don't want to have to update both datasources all the time)

Thanks,
Justin

2 Answers, 1 is accepted

Sort by
0
Accepted
Tina Stancheva
Telerik team
answered on 06 Jan 2011, 03:45 PM
Hi Justin Lee,

When the RAdTreeView control is data bound, you can control the vizualization of its data source through the ItemTemplate property. When you define a HierarchicalDataTemplate, the TreeView will visualize its data hierarchicly. However, when you define a DataTemplate the data will be displayed as flat collection. Therefore, in your case you can defiene one HierarchicalTemplate for the second treeview and set its ItemTemplate to a DataTemplate, for example like so:
<UserControl.Resources>
       <DataTemplate x:Key="SecondLevelTemplate">
           <TextBlock Text="{Binding MyValue}" />
       </DataTemplate>
       <telerik:HierarchicalDataTemplate x:Key="FirstLevelTemplate"
                                         ItemsSource="{Binding Items}"
                                         ItemTemplate="{StaticResource SecondLevelTemplate}">
           <TextBlock Text="{Binding MyValue}" />
       </telerik:HierarchicalDataTemplate>
   </UserControl.Resources>
   <Grid x:Name="LayoutRoot"
         Background="White">
       <telerik:RadTreeView ItemsSource="{Binding MyData}"
                            ItemTemplate="{StaticResource FirstLevelTemplate}" />
   </Grid>
This way the second-level data will be display as a flat collection.

Give this a try and let us know if it works for you.

All the best,
Tina Stancheva
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Justin Lee
Top achievements
Rank 1
answered on 06 Jan 2011, 03:54 PM
That worked perfectly. Thanks!
Tags
TreeView
Asked by
Justin Lee
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Justin Lee
Top achievements
Rank 1
Share this question
or