• 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);
                }
            }

  • 相关阅读:
    智能手机
    Micro LED
    paper-10-IRM-in-MANETs
    INFOCOM
    如何基于 Android Things 构建一个智能家居系统?
    (OK) VNCserver
    CCF 2016-04-2 俄罗斯方块
    CCF 2016-04-1 折点计数
    洛谷 P1927 防护伞
    洛谷 P1843 奶牛晒衣服
  • 原文地址:https://www.cnblogs.com/skyblue/p/955132.html
Copyright © 2020-2023  润新知