Button 对 TreeView1 所有节点的全选

protected void Button1_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < this.TreeView1.Nodes.Count; i++)//循环根节点
        {
            if (TreeView1.Nodes[i].Checked == false)//判断是否被选中
            {
                TreeView1.Nodes[i].Checked = true;
                for (int j = 0; j < this.TreeView1.Nodes[i].ChildNodes.Count; j++)//循环当前节点的第一级子节点
                {
                    if (this.TreeView1.Nodes[i].ChildNodes[j].Checked == false)
                    {
                        TreeView1.Nodes[i].ChildNodes[j].Checked = true;
                    }
                }
            }
        }
    } 

posted on 2016-02-06 13:50  _jimmy  阅读(855)  评论(0编辑  收藏  举报

导航