Get list of all checked nodes and its subnodes in treeview

前端 未结 3 1575
陌清茗
陌清茗 2020-12-19 02:30

I have a treeview list check boxes and the list contains nodes, subnodes and in some cases subnode of subnode. When user check some items i want to get list of selected item

3条回答
  •  粉色の甜心
    2020-12-19 02:34

    public void GetCheckedNodes(TreeNodeCollection nodes)
    {
        foreach(System.Windows.Forms.TreeNode aNode in nodes)
        {
             //edit
             if(!aNode.Checked)
                 continue;
    
             Console.WriteLine(aNode.Text);
    
             if(aNode.Nodes.Count != 0)
                 GetCheckedNodes(aNode.Nodes);
        }
    } 
    

    You don't make look back into the child notes, using recursion you can do it.

    You need method like this ! In your code just call once GetCheckedNodes(tvSastavnica.Nodes) and all checked nodes should be displayed !

提交回复
热议问题