newbie: displaying generic collection in TreeView

Discussion in 'ASP .Net' started by Jeff, Dec 9, 2008.

  1. Jeff

    Jeff Guest

    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;
    }
    }
     
    Jeff, Dec 9, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven Baggs
    Replies:
    5
    Views:
    43,412
    Steven Baggs
    Oct 18, 2005
  2. Murat Tasan
    Replies:
    1
    Views:
    8,097
    Chaitanya
    Feb 3, 2009
  3. Replies:
    2
    Views:
    460
  4. Øyvind Isaksen
    Replies:
    1
    Views:
    1,012
    Øyvind Isaksen
    May 18, 2007
  5. minlearn
    Replies:
    2
    Views:
    477
    red floyd
    Mar 13, 2009
Loading...

Share This Page