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

Automatically add missing parent nodes

1 Answer 60 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Chris Ward
Top achievements
Rank 1
Chris Ward asked on 30 Apr 2014, 08:36 PM
I was expecting that calling AddNodeByPath would automatically create the necessary parent nodes similar to how Directory.Create() works.

treeView.AddNodeByPath("General\\Billing\\February\\Report.txt")
treeView.AddNodeByPath("General\\Billing\\March\\Report.txt")
treeView.AddNodeByPath("General\\Billing\\April\\Report.txt")

However, it just seems to add them all to the closest node it could find (if there are no nodes, then a bunch of "Report.txt" will be in the root node).

I have come up with the following to solve this issue, but I'm wondering if there's an easier way?

private RadTreeNodeCollection AddNode(string path)
{
    if (path == String.Empty)
        return treeView.Nodes;
 
    string node = Path.GetFileName(path);
    RadTreeNodeCollection parent = AddNode(Path.GetDirectoryName(path));
 
    if (parent.Contains(node))
        return parent[node].Nodes;
    else
        return parent.Add(node).Nodes;
}

Is this a bug, or is it documented somewhere that AddNodeByPath() doesn't create the necessary parent nodes?

1 Answer, 1 is accepted

Sort by
0
George
Telerik team
answered on 01 May 2014, 02:22 PM
Hello Chris,

Thank you for contacting us.

We consider that the AddNodeByPath method should create parent nodes where they do not exist. That is why I have logged it in our Feedback Portal. You can find it on the following url: UI for Winforms Feedback Portal - FIX. RadTreeView - AddNodeByPath does not create parent nodes if they do not exist. Feel free to add your votes/comments or subscribe for changes.

I have updated Telerik Points to your account as a token of gratitude for your report.

Let me know if you have further questions.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
Treeview
Asked by
Chris Ward
Top achievements
Rank 1
Answers by
George
Telerik team
Share this question
or