how to set treeview child nodes of child nodes of child nodes ... etc.. in loop

Jan 25 2008 1:04 PM
I am doing a foreach loop where I add nodes to a treeview control. When

            TreeNode treeNode;

            foreach (Item item in stuff)
            {
                      treeNode = this.TreeView.Nodes.Add("label");
            }

What I want to do is put a conditional in the loop that, if true, it adds any following nodes in the loop as child nodes to that treeNode where the conditional is true. I can do this for a single occurence where the conditional is true, but how can I do it if it is true WITHIN a node that is already a child? Ie. make a child node of a child node of a child node and so on... instead of doing it manually like Nodes.Nodes.Nodes.Nodes. etc...

Thanks


Answers (4)