• Devexpress TreeList控件的相关操作


    /// <summary>
            /// 获取整棵树的所有选中的节点
            /// </summary>
            /// <param name="treeList"></param>
            /// <returns></returns>
            private List<DNode.TreeListNode> GetSelectedNodes(DevExpress.XtraTreeList.TreeList treeList)
            {
                List<DNode.TreeListNode> sNodes = new List<DNode.TreeListNode>();
                List<DNode.TreeListNode> allNodes = GetAllNode(treeList);
                foreach(DNode.TreeListNode node in allNodes)
                {
                    if (node.Checked)
                        sNodes.Add(node);
                }
                return sNodes;
            }
    

      

    /// <summary>
            /// 获取node节点及其子孙节点的数据
            /// </summary>
            /// <param name="node"></param>
            /// <param name="list"></param>
            private void GetAllDescendantData(DevExpress.XtraTreeList.Nodes.TreeListNode node, ref List<ObjectPermissionItem> list)
            {
                ObjectPermissionItem data = treeList1.GetDataRecordByNode(node) as ObjectPermissionItem;
                if (data != null)
                    list.Add(data);
                if (node.Nodes.Count > 0)
                {
                    foreach (DevExpress.XtraTreeList.Nodes.TreeListNode cnode in node.Nodes)
                        GetAllDescendantData(cnode, ref list);
                }
            }
    

      

    /// <summary>
            /// 获取treeList的所有节点
            /// </summary>
            /// <param name="treeList"></param>
            /// <returns></returns>
            private List<DevExpress.XtraTreeList.Nodes.TreeListNode> GetAllNode(DevExpress.XtraTreeList.TreeList treeList)
            {
                List<DevExpress.XtraTreeList.Nodes.TreeListNode> allNodes = new List<DevExpress.XtraTreeList.Nodes.TreeListNode>();
                foreach(DevExpress.XtraTreeList.Nodes.TreeListNode node in treeList.Nodes)
                {
                    allNodes.Add(node);
                    List<DNode.TreeListNode> cnode = new List<DNode.TreeListNode>();
                    DoGetNodes(ref cnode, node);
                    allNodes.AddRange(cnode);
                }
                return allNodes;
            }
    

      

    /// <summary>
            /// 递归获取parentNode节点的所有子孙节点
            /// </summary>
            /// <param name="list"></param>
            /// <param name="parentNode"></param>
            private void DoGetNodes(ref List<DevExpress.XtraTreeList.Nodes.TreeListNode> list,DevExpress.XtraTreeList.Nodes.TreeListNode parentNode)
            {
                foreach(DNode.TreeListNode node in parentNode.Nodes)
                {
                    list.Add(node);
                    if(node.Nodes.Count>0)
                    {
                        DoGetNodes(ref list, node);
                    }
                }
            }
    

      

    /// <summary>  
            /// 设置子节点的状态  
            /// </summary>  
            /// <param name="node"></param>  
            /// <param name="check"></param>  
            private void SetCheckedChildNodes(DevExpress.XtraTreeList.Nodes.TreeListNode node, CheckState check)
            {
                for (int i = 0; i < node.Nodes.Count; i++)
                {
                    node.Nodes[i].CheckState = check;
                    SetCheckedChildNodes(node.Nodes[i], check);
                }
            }
    
            /// <summary>  
            /// 设置父节点的状态  
            /// </summary>  
            /// <param name="node"></param>  
            /// <param name="check"></param>  
            private void SetCheckedParentNodes(DevExpress.XtraTreeList.Nodes.TreeListNode node, CheckState check)
            {
                if (node.ParentNode != null)
                {
                    bool b = false;
                    CheckState state;
                    for (int i = 0; i < node.ParentNode.Nodes.Count; i++)
                    {
                        state = (CheckState)node.ParentNode.Nodes[i].CheckState;
                        if (!check.Equals(state))
                        {
                            b = !b;
                            break;
                        }
                    }
                    node.ParentNode.CheckState = b ? CheckState.Indeterminate : check;
                    SetCheckedParentNodes(node.ParentNode, check);
                }
            }  
    

      

    /// <summary>
            /// 点击一个节点,刷新其子节点和父节点的选中状态
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void treeList1_AfterCheckNode(object sender, DevExpress.XtraTreeList.NodeEventArgs e)
            {
                SetCheckedChildNodes(e.Node, e.Node.CheckState);
                SetCheckedParentNodes(e.Node, e.Node.CheckState);  
            }
    

      

  • 相关阅读:
    资源:mysql下载路径
    知识点:jar包与war包的差异
    Linux:jar服务部署
    Flyway:Spring Boot中使用Flyway来管理数据库版本
    Java:Java控制台输出保存进文件
    Maven:手动添加jar包进Maven本地库内
    Https:SSL双向认证机制(理论知识)
    Linux ubuntu 下寻找 texlive 缺失包 texlive 缺失包(转载)
    Android应用开发提高篇(4)-----Socket编程(多线程、双向通信)(转载)
    Android应用开发基础篇(12)-----Socket通信(转载)
  • 原文地址:https://www.cnblogs.com/wangzuofei/p/5773265.html
Copyright © 2020-2023  润新知