This is a migrated thread and some comments may be shown as answers.

Treeview not displaying items from generic list?

4 Answers 216 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ogie Chu
Top achievements
Rank 1
Ogie Chu asked on 26 Oct 2009, 12:04 PM
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

4 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 26 Oct 2009, 01:43 PM
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.
0
Ogie Chu
Top achievements
Rank 1
answered on 27 Oct 2009, 09:10 AM
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
0
Ogie Chu
Top achievements
Rank 1
answered on 28 Oct 2009, 06:18 AM
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.

0
Neil Timmerman
Top achievements
Rank 2
answered on 24 Dec 2009, 04:26 PM
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.
Tags
TreeView
Asked by
Ogie Chu
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Ogie Chu
Top achievements
Rank 1
Neil Timmerman
Top achievements
Rank 2
Share this question
or