Treeview not displaying items from generic list?

5 posts, 0 answers
  1. Ogie Chu
    Ogie Chu avatar
    3 posts
    Member since:
    Oct 2009

    Posted 26 Oct 2009 Link to this post

    Hi,
    I uploaded my sample project to show that there's some problems when binding my generic list to the treeview. It's not showing anything even though the DataSource item count of the Treeview is 2 (more than 0).

    Kindly check the project on this link: 

    I'm using Q2 2009 .Net 3.5

    Thanks,
    Ogie
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 26 Oct 2009 Link to this post

    Hello Ogie Chu,

    The nodes are not displayed because the root node should have its ParentID equal to null.
    Here is what you need to do:

    1. Change the ParentID property to allow null values:

    public Guid? ParentId { get; set; }

    2. Set the ParentID property of the root item to null:

    a.ParentId = null;

    Hope this helps.

    All the best,
    Veselin Vasilev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Ogie Chu
    Ogie Chu avatar
    3 posts
    Member since:
    Oct 2009

    Posted 27 Oct 2009 Link to this post

    Hi Veselin Vasilev,

    Thanks for your quick reply.
    In order to fully understand what you have said I will try to re-elaborate it.

    The nodes can not be displayed because the ParentId is NOT NULL right?
    I need to set my ParentId as NULL in order for me to set it as the main node right?

    I have updated my project to show you that even if my ParentId is NOT NULL, I can still see it by using an Empty GUID value.
    Does it have any special functionality when it detects the type of GUID on the Treeview?


    The problem is, I need to retrieve a specific records then I will display it in Treeview. If the ParentId of an item is not included in the list, it should be created as a main node.


    Thanks,
    Ogie
  4. Ogie Chu
    Ogie Chu avatar
    3 posts
    Member since:
    Oct 2009

    Posted 28 Oct 2009 Link to this post

    I found a workaround to fix my problem regarding this issue. I just want to share the updated project to whoever will encounter the same issue.
    I just hope this will be automatic on the treeview since it's logical to make the node MAIN if it's parent is not existing.

  5. Neil Timmerman
    Neil Timmerman avatar
    2 posts
    Member since:
    Nov 2009

    Posted 24 Dec 2009 Link to this post

    Yes, Ogie Chu is right, I am experiencing this problem exactly. Ogie I ran your test project and it demonstrates the bug perfectly.

    I chose the approach of using a nullable integer as my parent ID (int?), which according to the documentation should work.

    if (!IsPostBack)  
                {  
     
                    NavigationMenuItem nmi1 = new NavigationMenuItem(2, null"Node 1""Default.aspx"null, 1, falsetruefalsefalsefalse);  
                    NavigationMenuItem nmi11 = new NavigationMenuItem(3, 2, "Node 1.1""ReportViewer"null, 1, truetruefalsefalsefalse);  
                    NavigationMenuItem nmi12 = new NavigationMenuItem(4, 2, "Node 1.2""ReportViewer"null, 2, truetruefalsefalsefalse);  
                    NavigationMenuItem nmi13 = new NavigationMenuItem(5, 2, "Node 1.3""ReportViewer"null, 3, truetruefalsefalsefalse);  
                    NavigationMenuItemCollection nmic = new NavigationMenuItemCollection();  
     
                    nmic.Add(nmi1);  
                    nmic.Add(nmi11);  
                    nmic.Add(nmi12);  
                    nmic.Add(nmi13);  
                   
                    RadTreeView1.DataTextField = "Name";  
                    RadTreeView1.DataValueField = "Id";  
                    RadTreeView1.DataNavigateUrlField = "NavigateUrl";  
                    RadTreeView1.DataFieldParentID = "ParentId";  
                    RadTreeView1.DataSource = nmic;  
     
                    RadTreeView1.DataBind();  
                } 

    Interestingly it works with IHierarchicalEnumerable generic collections, but not IEnumerable generic collections.
Back to Top