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

Recursive creation of nodes

0 Answers 76 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Reiner Ebel
Top achievements
Rank 1
Reiner Ebel asked on 10 Apr 2010, 05:59 PM

Hello,

When I create nodes I have a problem. I have a list:

e.g.:



class Liste  
{  
    public string pfad;  
    public Liste(string pfad)  
    {  
        this.pfad = pfad;  
    }  
}  
 
....  
 
if (!IsPostBack)  
{  
    LadeWerte();  
    ZeigeTreeView();  
}  
 
.....  
 
private void LadeWerte()  
{  
liste.Add(new Liste("c:\\dateien\\nord\\stad_nord"));  
liste.Add(new Liste("c:\\dateien\\stad_test"));  
liste.Add(new Liste("c:\\dateien\\nord\\stad_sued"));  
}  
 
 

From this list, I create nodes. Here is my code:

private void ZeigeTreeView()  
    {  
        RadTreeNode rtn = new RadTreeNode("Layouts""rootfolder");  
 
        foreach (Liste list in liste)  
        {  
            Rekursiv(rtn, list.pfad);              
        }  
 
        RadTreeView1.Nodes.Add(rtn);  
    }  
 
    private void Rekursiv(RadTreeNode node, string newnode)  
    {  
        if (newnode != "")  
        {  
            RadTreeNode rtn2 = new RadTreeNode();  
            string substr = "";  
            if (newnode.LastIndexOf("\\") > 0)  
                substr = newnode.Substring(0, newnode.IndexOf("\\"));  
            else 
                substr = newnode;  
            rtn2.Text = substr;  
            rtn2.Value = "Folder";  
            string nextnode = "";  
            if (newnode.IndexOf("\\") > 0)  
            {  
                nextnode = newnode.Substring(newnode.IndexOf("\\") + 1);  
                Rekursiv(rtn2, nextnode);  
            }  
            node.Nodes.Add(rtn2);  
        }  
    } 

I get the following structure:

+Layouts
    +c:
        +dateien
            +nord
                -stadt_nord
    +c:
        +dateien
            -stad_test
    +c:
        +dateien
            +nord
                -stad_sued

However, I want the following structure:

+Layouts
    +c:
        +dateien
        -stad_test
        +nord
            -stad_nord
            -stad_sued

Can you help me here? Nodes that should already exist are not created again. How can I do that.

Thanks

Reiner

No answers yet. Maybe you can help?

Tags
TreeView
Asked by
Reiner Ebel
Top achievements
Rank 1
Share this question
or