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;
}
}
..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;
}
}