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

How to bind this data to a TreeView?

1 Answer 25 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Manfred
Top achievements
Rank 2
Manfred asked on 16 Mar 2011, 11:30 AM
Hi there,

I have the following structure of data:
public class Entry
{
  public string Name;
  public string Descrption;
  public bool IsDirectory;
  public string PathToFile;
  public List<Entry> Entries;
}
I got a List<Entries> which contains several Entries which contains also List<Entries>.
This is to show a folder structure and the files in it to create links for downloads.
How can I bind this to a TreeView to visualize this data and if it is a file to create it as a link?

Best Regards
Manfred

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 19 Mar 2011, 12:16 PM
Hi Manfred,

I prepared a sample project for you that shows a possible approach to your requirements. Firs of all , it is better to bind the RadTreeView with ObservableCollection, since they inherit from INotifyPropertyChanged and INotifyCollectionChanged and every change in the ViewModel reflects the UI immediately. I used HierarChicalDataTemplate for the Folders (which have children) and DataTemplate for the Files and ItemTemplateSelector. When the RadTreeViewItem is generated , the SelectTemplate() of the TemplateSelecor fires and the business Object (Entry) is passes in the "item" argument. Then by checking the IsDiretory, the correct template is chosen. Please examine the projet and let us know if it satisfies you.

All the best,
Petar Mladenov
the Telerik team
Tags
TreeView
Asked by
Manfred
Top achievements
Rank 2
Answers by
Petar Mladenov
Telerik team
Share this question
or