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

RadTreeView Only display ROOT nodes

1 Answer 196 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Oğulcan
Top achievements
Rank 1
Oğulcan asked on 24 Nov 2017, 09:23 PM

Hello, i have really simple RadTreeView control. 

but there is an issue, nodes only display if they have "0" ParentID. I put the code like telerik's examples and also table content is correct.

Why i cant put any child nodes which their ParentID is ParentID > 0


var ds = db.Finding.AsQueryable().ToList();
 
treeView.DataTextField = "VulnerabilityCode";
treeView.DataValueField = "ScanId";
treeView.DataFieldID = "Id";
treeView.DataFieldParentID = "ParentId"; // only shows where this value is ZERO
treeView.DataSource = ds;
treeView.DataBind();

 

<telerik:RadPane runat="server" Scrolling="None">
                        <telerik:RadSplitter runat="server" Orientation="Horizontal">
                            <telerik:RadPane runat="server">
                                <telerik:RadTreeView ID="RadTreeView2" IsExpanded="True" runat="server" Skin="WebBlue" Height="600px" Width="100%">
                                </telerik:RadTreeView>
                            </telerik:RadPane>
...

 

1 Answer, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 29 Nov 2017, 01:38 PM
Hello Oğulcan,

Would you please check again if the Data in the ds collection is correct? The ParentId value has to be either 0 (or null, when the type of Id is string) or an Id of an existing node.

Please find attached a sample project that works as expected - https://www.screencast.com/t/IFk8TPRVJ61.

<telerik:RadTreeView ID="treeView" IsExpanded="True" runat="server" Height="600px" Width="100%">
</telerik:RadTreeView>
public static int index { get; set; }
 
public class Vulnerability
{
    public string VulnerabilityCode { get; set; }
    public int ScanID { get; set; }
    public int Id { get; set; }
    public int ParentId { get; set; }
 
}
 
protected void Page_Load(object sender, EventArgs e)
{
    var ds = GetVulnerabilities();
 
    treeView.DataTextField = "VulnerabilityCode";
    treeView.DataValueField = "ScanId";
    treeView.DataFieldID = "Id";
    treeView.DataFieldParentID = "ParentId"; // only shows where this value is ZERO
    treeView.DataSource = ds;
    treeView.DataBind();
}
 
private List<Vulnerability> GetVulnerabilities()
{
    var roots = new List<Vulnerability>();
    var allItems = new List<Vulnerability>();
    index = 1;
    var random = new Random();
    for (int i = 0; i < 5; i++)
    {
        roots.Add(new Vulnerability() { Id = index, ParentId = 0, ScanID = random.Next(), VulnerabilityCode = "Vulnerability " + index });
        index++;
    }
    allItems.AddRange(roots);
 
    var firstLevel = AddChildren(roots);
    allItems.AddRange(firstLevel);
 
    var secondLevel = AddChildren(firstLevel);
    allItems.AddRange(secondLevel);
 
    return allItems;
}
 
private static List<Vulnerability> AddChildren(List<Vulnerability> roots)
{
    var random = new Random();
    var items = new List<Vulnerability>();
    foreach (var item in roots)
    {
        for (int i = 0; i < 5; i++)
        {
            items.Add(new Vulnerability() { Id = index, ParentId = item.Id, ScanID = random.Next(), VulnerabilityCode = "Vulnerability " + index });
            index++;
        }
    }
 
    return items;
}

Regards,
Peter Milchev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
TreeView
Asked by
Oğulcan
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Share this question
or