且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在我的树形视图中选择一个子节点

更新时间:2023-02-09 09:12:25

private void button2_Click(object sender, EventArgs e)
    {
        int grandTotal = CalculateNodes(this.treeView1.Nodes);
    }
    private int CalculateNodes(TreeNodeCollection nodes)
    {
        int grandTotal = 0;
        foreach (TreeNode node in nodes)
        {
            if (node.Nodes.Count > 0)
            {
                int childTotal = CalculateNodes(node.Nodes);
                node.Text = childTotal.ToString();
                grandTotal += childTotal;
            }
            else
            {
                grandTotal += Convert.ToInt32(node.Text);
            }
        }
        return grandTotal;
    }


希望对您有帮助


Hope It Will Help You