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

Have element of differents types in a recursive tree?

3 Answers 98 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Julien
Top achievements
Rank 1
Julien asked on 24 Aug 2010, 09:26 AM
Hi!

I've to create a tree that represent Files and Folder.

my actual structure is:

Folder object has
-->SubFolder ObservableCollection
-->File List (observablecollection too)

I need to have in the same tree files and folder.

I've no problem creating a treee browsing Folders:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Grid.Resources>
        <HierarchicalDataTemplate x:Key="NodeTemplate" ItemsSource="{Binding SubFolders}">
            <TextBlock Text="{Binding Name}"/>
        </HierarchicalDataTemplate>
    </Grid.Resources>
    <telerik:RadTreeView Name="uxRadTreeView" ItemsSource="{Binding RootFolder.SubFolders}" ItemTemplate="{StaticResource NodeTemplate}" AllowDrop="False" IsDragDropEnabled="True" DragEnded="uxRadTreeView_DragEnded" />
</Grid>

But how can I get files with that too?

They both have a "Name" property


3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 25 Aug 2010, 05:39 PM
Hello Julien,

You just need to create an additional property (AllItems of type ObservableCollection) that contains both files and folders lists and use that property in the data binding.

<HierarchicalDataTemplate x:Key="NodeTemplate" ItemsSource="{Binding AllItems}">
    <TextBlock Text="{Binding Name}"/>
</HierarchicalDataTemplate>

Also, you can use ItemTemplateSelector property of the RadTreeView instead of using ItemTemplate. This way you will be able to apply different data templates to different items in the tree based on custom logic. I'm attaching a sample project demonstrating what I mean.

Kind regards,
Hristo Milyakov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Julien
Top achievements
Rank 1
answered on 26 Aug 2010, 07:23 AM
But I've to maintain updated theses two properties,

And I can't open the ExpressionTree, I got a strange error: C:\Users\julien\Desktop\test\ExpressionTree\ExpressionTree.csproj : error  : Unable to read the project file 'ExpressionTree.csproj'. 

ExpressionTree.Web hasn't this problem
0
Hristo
Telerik team
answered on 27 Aug 2010, 08:53 AM
Hello Julien,

Yes, you have to maintain the collections synchronized.

The project I sent you was a Silverlight project I've attached by mistake. You can take a look at the following attachment, which is a WPF project using framework version 3.5.

Greetings,
Hristo Milyakov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
Julien
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Julien
Top achievements
Rank 1
Share this question
or