Want different node name from path generated

5 posts, 0 answers
  1. George
    George avatar
    5 posts
    Member since:
    Apr 2008

    Posted 05 May 2009 Link to this post


    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?:


    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.

  2. Victor
    Victor avatar
    1358 posts

    Posted 07 May 2009 Link to this post

    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()  
            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";  
        void TraverseNodes(RadTreeNodeCollection nodes)  
            foreach (RadTreeNode n in nodes)  
                if (n.Nodes.Count == 0)  
        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,
    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.
  3. George
    George avatar
    5 posts
    Member since:
    Apr 2008

    Posted 08 May 2009 Link to this post

    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,

  4. Deepesh
    Deepesh avatar
    3 posts
    Member since:
    Nov 2010

    Posted 19 Nov 2010 Link to this post


    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 ?
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 19 Nov 2010 Link to this post


    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
Back to Top