TreeView populated from string array?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hooliovelasko
    New Member
    • Jul 2008
    • 2

    #1

    TreeView populated from string array?

    Hello my fellow experts, I use c# and windows forms. I have array of two or more strings. How to add them into treeview(first is root, second is child of root, third is subchild of child and so on..)
    Example:
    string [] names = new string[] {"Root", "Child", "SubChild"} ;

    should i use some recursive method or ...?

    Root
    |---------Child
    |------------SubChild

    Thank you in advance!
  • misza
    New Member
    • Feb 2008
    • 13

    #2
    This is an example from http://msdn.microsoft. com/en-us/library/system.windows. forms.treeview( VS.80).aspx on how to populate the treeview

    // Populates a TreeView control with example nodes.
    private void InitializeTreeV iew()
    {
    treeView1.Begin Update();
    treeView1.Nodes .Add("Parent");
    treeView1.Nodes[0].Nodes.Add("Chi ld 1");
    treeView1.Nodes[0].Nodes.Add("Chi ld 2");
    treeView1.Nodes[0].Nodes[1].Nodes.Add("Gra ndchild");
    treeView1.Nodes[0].Nodes[1].Nodes[0].Nodes.Add("Gre at Grandchild");
    treeView1.EndUp date();
    }

    Let me know if you still need help with your query.

    Thanks,
    michal

    Comment

    Working...