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

Want different node name from path generated

4 Answers 74 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
George
Top achievements
Rank 1
George asked on 05 May 2009, 10:47 PM
Hi,

I have a RadTreeView with a list of nodes, each of which should have a count after them.

Root (10)
-- Cars (20)
---- Ford (12)
---- Chrysler (2)
---- GM (30)

I realize I can use the tag to store a "value" for the node independent of the display format - I'm already doing that.  However, when I export the data in the table, I make use of the convenient "Path" property to flatten out the hierarchy.  Is there a way to generate the Path from the Tag property rather than from the Text property?

How would you go about exporting this to a list that looks like this?:

Root
Root/Cars
Root/Cars/Ford
Root/Cars/Chrysler
Root/Cars/GM

I'd rather not write the code to walk the tree and construct the paths myself - but it's the most practical solution I can think of.

4 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 07 May 2009, 02:15 PM
Hello George,

Thank you for writing. I am afraid that we did not design the tree nodes to be able to create a path from Tag or from another random property -- you can do it with code though. It does not sound too difficult, you just need to traverse up through the parent chain for each leaf node and create the string.

Here is some sample code:

public partial class Form1 : Form  
{  
    List<string> pathList = new List<string>();  
    public Form1()  
    {  
        InitializeComponent();  
        this.radTreeView1.Nodes[0].Tag = "C:";  
        this.radTreeView1.Nodes[0].Nodes[0].Tag = "Games";  
        this.radTreeView1.Nodes[0].Nodes[0].Nodes[0].Tag = "UnealTournament3";  
        this.radTreeView1.Nodes[0].Nodes[0].Nodes[0].Nodes[0].Tag = "Bin";  
 
        TraverseNodes(this.radTreeView1.Nodes);  
        MessageBox.Show(pathList[0]);  
    }  
 
    void TraverseNodes(RadTreeNodeCollection nodes)  
    {  
        foreach (RadTreeNode n in nodes)  
        {  
            if (n.Nodes.Count == 0)  
            {  
                pathList.Add(CreatePathFromTag(n));  
            }  
            TraverseNodes(n.Nodes);  
        }  
    }  
 
    string CreatePathFromTag(RadTreeNode n)  
    {  
        StringBuilder builder = new StringBuilder();  
        while (n != null)  
        {  
            builder.Insert(0, n.Tag.ToString() + n.TreeView.PathSeparator);  
            n = n.Parent;  
        }  
 
        // Remove the separator that would appear after the end of the path.  
        builder.Remove(builder.Length - 1, 1);  
        return builder.ToString();  
    }  

Please write back if you need further assistance.

Sincerely yours,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
George
Top achievements
Rank 1
answered on 08 May 2009, 02:58 PM
Dear Viktor,

That's exactly what I expected - but I had to ask in case there was something basic that I missed.  

Thank you for your prompt reply, and especially thank you for providing the sample code with a workaround.  You guys provide exceptional support on these forums.

Best Regards,
George


0
Deepesh
Top achievements
Rank 1
answered on 19 Nov 2010, 08:50 AM
Team,

can i format a tree view text like

my tree view node is like
---My String (1234)

so please tell me can i bold this 1234 if yes then please suggest How ?
0
Richard Slade
Top achievements
Rank 2
answered on 19 Nov 2010, 12:28 PM
Deepesh,

Please see your reply in this thread. May I suggest also asking a question in one thread only as you may get a slower response as a result.

All the best
Richard
Tags
Treeview
Asked by
George
Top achievements
Rank 1
Answers by
Victor
Telerik team
George
Top achievements
Rank 1
Deepesh
Top achievements
Rank 1
Richard Slade
Top achievements
Rank 2
Share this question
or