zoukankan      html  css  js  c++  java
  • 加载TreeView并设置复选框

            /// <summary>
            /// 加载父结点
            /// </summary>
            private void LoadFirstNodes()
            {
                BLLPResource resource = new BLLPResource();
                List<ModPResource> firstNodeList = resource.GetFirstNodes();
                if (firstNodeList != null && firstNodeList.Count > 0)
                {
                    foreach (ModPResource r in firstNodeList)
                    {
                        TreeNode treeNode = new TreeNode();
                        treeNode.Name = r.Resourceid.ToString();
                        treeNode.Text = r.MenuText;
                        LoadSubNodes(treeNode);
                        this.tvPower.Nodes.Add(treeNode);
                    }
                }
            }

            /// <summary>
            /// 加载子结点
            /// </summary>
            /// <param name="node"></param>
            private void LoadSubNodes(TreeNode node)
            {
                if (node != null )
                {
                    BLLPResource resource = new BLLPResource();
                    string menuParent = node.Name;
                    List<ModPResource> subNodeList = resource.GetSubNodes(menuParent);
                    foreach (ModPResource r in subNodeList)
                    {
                        TreeNode subNode = new TreeNode();
                        subNode.Text = r.MenuText;
                        subNode.Name = r.Resourceid.ToString();
                        LoadSubNodes(subNode);
                        node.Nodes.Add(subNode);
                    }
                }
            }


            /// <summary>
            /// 设置所有父节点为未勾选
            /// </summary>
            /// <param name="node"></param>
            private void ClearFirstChecked()
            {
                foreach (TreeNode node in tvPower.Nodes)
                {
                    node.Checked = false;
                    ClearSubChecked(node);
                }
            }
            /// <summary>
            /// 设置所有子节点为未勾选
            /// </summary>
            /// <param name="node"></param>
            private void ClearSubChecked(TreeNode node)
            {
                if (node.Nodes != null)
                {
                    foreach (TreeNode subNode in node.Nodes)
                    {
                        subNode.Checked = false;
                        ClearSubChecked(subNode);
                    }
                }
            }
            /// <summary>
            /// 设置父结点Checked
            /// </summary>
            private void SetFirstChecked(string roleid)
            {
                //取消所有勾选项
                ClearFirstChecked();
                
                prole_presource = new BLLPRole_PResource();
                list= prole_presource.GetAll(roleid);
                if (list != null && list.Count > 0)
                {
                    foreach (TreeNode node in this.tvPower.Nodes)
                    {
                        //此节点是否要被选中的中间变量
                        //如果此节点在list中存在就设置为true
                        bool isCheck = false;
                        foreach (ModPRole_PResource mod in list)
                        {
                            if (node.Name == mod.Resourceid.ToString())
                            {
                                isCheck = true;
                                SetSubChecked(node);
                                break;
                            }
                        }
                        node.Checked = isCheck;
                    }
                    
                        
                }            
            }
            /// <summary>
            /// 设置子结点Checked
            /// </summary>
            private void SetSubChecked(TreeNode node)
            {
                if (node != null && node.Nodes.Count > 0)
                {
                    foreach (TreeNode subNode in node.Nodes)
                    {
                        //此节点是否要被选中的中间变量
                        //如果此节点在list中存在就设置为true
                        bool isCheck=false;
                        foreach (ModPRole_PResource mod in list)
                        {
                            if (subNode.Name == mod.Resourceid.ToString())
                            {
                                isCheck = true;
                                SetSubChecked(subNode);
                                break;
                            }                        
                        }
                        subNode.Checked = isCheck;
                    }

                }
            }      

    From:http://blog.csdn.net/inc_root/archive/2008/11/13/3294551.aspx

  • 相关阅读:
    一些易忘记的常识HTML,不定期添加
    base64 encoder/decoder for objectivec编码及解码(转)
    用XCode 开发基于网络库ACE的应用
    迅雷/旋风地址转换原理分析(转)
    主题:非常常用的Mac快捷键
    没事干测试ObjC数据类型
    These are the support and errata files for titles formerly published by Wrox Press Limited.
    iOS 开发者应该知道的 ARM 结构(转自apple4us)
    [创建型模式] Factory
    [创建型模式] Builder
  • 原文地址:https://www.cnblogs.com/no7dw/p/1534525.html
Copyright © 2011-2022 走看看