Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tree Collection in .NET

When I make a list box in WPF I frequently set its ItemsSource to be a List. Is there a Tree for TreeView (or what goes in ItemsSource for TreeView)?

Is there a collection or generally accepted method for handling tree data in C#.NET?

like image 664
Vaccano Avatar asked Jan 20 '10 21:01

Vaccano


People also ask

Does C# have a tree class?

In the C# language a tree can be implemented with classes (nodes) that point to further nodes. In this simple implementation, we use a Dictionary. AddWord This method takes a string argument and adds it to the tree by creating (or using existing) nodes (one per character).


2 Answers

What you want to do is bind a collection of hierarchical objects to the tree view using the Hierarchical Data Template.

I have written a blog post on this very subject, check it out,

Displaying Hierarchical Data with the WPF Tree View control

like image 193
mattdlong Avatar answered Sep 24 '22 03:09

mattdlong


Nothing built in as far as I know. What I usually do is something like this:

class User  
{  
string Name { get; set; }  
List<User> { get; set; }  
}  

Then you can use that to bind to your hierarchical control, such as a TreeView.

like image 39
Henrik Söderlund Avatar answered Sep 23 '22 03:09

Henrik Söderlund