zoukankan      html  css  js  c++  java
  • TreeView的checked事件

        /// <summary>
            /// TreeView checked事件
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void tvMenu_AfterCheck(object sender, TreeViewEventArgs e)
            {
                CheckAll(e.Node);
            }

            /// <summary>
            /// 全部节点check处理
            /// </summary>
            /// <param name="eTreeNode"></param>
            private void CheckAll(TreeNode eTreeNode)
            {
                tvMenu.AfterCheck -=new TreeViewEventHandler(tvMenu_AfterCheck);
                if (eTreeNode.Parent != null)
                {
                    CheckParent(eTreeNode);
                }
                if (eTreeNode.Nodes.Count > 0)
                {
                    foreach (TreeNode mTN in eTreeNode.Nodes)
                    {
                        mTN.Checked = eTreeNode.Checked;
                       
                        foreach (TreeNode mTNSub in mTN.Nodes)
                        {
                            mTNSub.Checked = mTN.Checked;
                            CheckSub(mTNSub);
                        }
                    }
                }
               
                tvMenu.AfterCheck += new TreeViewEventHandler(tvMenu_AfterCheck);
            }
            /// <summary>
            /// 父节点处理
            /// </summary>
            /// <param name="eTreeNode"></param>
            private void CheckParent(TreeNode eTreeNode)
            {
                if (eTreeNode.Parent == null)
                {
                    return;
                }
               
                eTreeNode.Parent.Checked = eTreeNode.Checked;
               
                foreach (TreeNode mTN in eTreeNode.Parent.Nodes)
                {
                    eTreeNode.Parent.Checked = (eTreeNode.Parent.Checked || mTN.Checked);
                    if (mTN.Parent != null)
                    {
                        CheckParent(mTN.Parent);
                    }
                }
            }
            /// <summary>
            /// 子节点处理
            /// </summary>
            /// <param name="eTreeNode"></param>
            private void CheckSub(TreeNode eTreeNode)
            {
                foreach (TreeNode mTN in eTreeNode.Nodes)
                {
                    mTN.Checked = eTreeNode.Checked;
                    CheckSub(mTN);
                }
            }

  • 相关阅读:
    UTF-8 GBK UTF8 GB2312 之间的区别和关系
    为什么要需求分析
    数据库建表原则
    使用SQL存储过程有什么好处 用视图有什么好处
    SQL使用视图的优缺点
    百度地图添加多个行政区划
    性能测试日志分析之awk基础用法
    Nginx 安装配置
    linux的top命令参数详解
    Java小程序Linux下运行
  • 原文地址:https://www.cnblogs.com/skyblue/p/955132.html
Copyright © 2011-2022 走看看