The C-sharp treeview control gets the child

treeview control in C-sharp winform
how to get leaves after 3 layers of selected items in treeview

Jun.20,2021

first get treeNode of Wang Sicong, then visit treeNode.Nodes recursive traversal, enter the next layer + 1, start at 3, and then traverse all the nodes you want.
Click


solved, return the leaf text after three layers.

 private List<string> GetChildList(TreeNode node, int level)
        {
            List<string> result = new List<string>(); ;

            //MessageBox.Show(level.ToString()+" " + node.Text);

            levelPP;

            if (node.Nodes.Count > 0)
            {
                foreach (TreeNode nod in node.Nodes)
                {
                    if (level > 3)
                    {
                        result.Add(nod.Text);
                    }

                    List<string> li = GetChildList(nod, level);

                    if (li.Count > 0)
                    {
                        foreach (string line in li)
                        {
                            result.Add(line);
                        }
                    }
                }
            }

            return result;
        }
Menu