newbie: displaying generic collection in TreeView


J

Jeff

Hi

..NET 3.5

I have a generic collection I want to display inside a TreeView control

This is how my class look like:
public class Comment
{
private Guid _id;
private Guid _userid;
private Guid _article;
private Guid _parent;
private List<Comment> _replies;

public comment() {}
}

my class can contain nested data. (_replies).

Problem strikes when I add this collection as the datasource of my TreeView,
I get this error:
"HierarchicalDataBoundControl only accepts data sources that implement
IHierarchicalDataSource or IHierarchicalEnumerable"

So I did some googling and came across this article:
http://www.codeproject.com/KB/custom-controls/IHierarchySupport.aspx?display=PrintAll

Based on that article, I extended my class. below u see the changes I
made... But still after these changes I get
"HierarchicalDataBoundControl only accepts data sources that implement
IHierarchicalDataSource or IHierarchicalEnumerable"

any suggestions?

public class Comment : IHierarchyData

public IHierarchicalEnumerable GetChildren()
{
CommentCollection children = new CommentCollection();

foreach(Comment comment in this.Replies) { children.Add(comment); }

return (IHierarchicalEnumerable)children; //this.Replies;
}

public IHierarchyData GetParent() { return this.Parent; }

public object Item { get { return this; } }

public string Path { get { return this.Id.ToString(); } }

public string Type { get { return this.GetType().ToString(); } }

public bool HasChildren
{
get
{
bool children = false;
if (this.Replies.Count > 0) children = true;
return children;
}
}
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top