zoukankan      html  css  js  c++  java
  • c# winform devexpress TreeList过滤和绑定

            /// <summary>
            /// 模糊查询
            /// </summary>
            /// <param name="str"></param>
            /// <param name="list"></param>
            /// <returns></returns>
            private IList<CV_QM_DEFECT_LABEL_GROUP> onFindKeyWord(string str, IList<CV_QM_DEFECT_LABEL_GROUP> list)
            {
    
                List<CV_QM_DEFECT_LABEL_GROUP> m_list = new List<CV_QM_DEFECT_LABEL_GROUP>();
                foreach (CV_QM_DEFECT_LABEL_GROUP data in list)
                {
                    if (data.GroupName.IndexOf(str) != -1)
                    {
                        m_list.Add(data);
                    }
                }
                return m_list;
    
            }
            /// <summary>
            /// 寻找所有相关根节点
            /// </summary>
            private List<CV_QM_DEFECT_LABEL_GROUP> findparent()
            {
                IList<CV_QM_DEFECT_LABEL_GROUP> entities = this.icv_QM_DEFECT_LABEL_GROUPBO_0.GetEntities();
                IList<CV_QM_DEFECT_LABEL_GROUP> filterdata = onFindKeyWord(txtquery.Text.Trim(), entities);
                List<CV_QM_DEFECT_LABEL_GROUP> entities1 = new List<CV_QM_DEFECT_LABEL_GROUP>();//转化为list方便使用方法
                List<CV_QM_DEFECT_LABEL_GROUP> entities2 = new List<CV_QM_DEFECT_LABEL_GROUP>();//用于存放所有节点
    
                foreach (var item in (IList<CV_QM_DEFECT_LABEL_GROUP>)entities)
                {
                    entities1.Add(item);
                }
                foreach (CV_QM_DEFECT_LABEL_GROUP data in filterdata)
                {
                    CV_QM_DEFECT_LABEL_GROUP temp1 = data;
                    while (true)
                    {
                        if (temp1.ParentGroupID.HasValue)
                        {
                            if (entities2.Find(s => s.GroupID.Equals(temp1.GroupID)) == null)
                            { entities2.Add(temp1); }
                            CV_QM_DEFECT_LABEL_GROUP temp = entities1.Find(s => s.GroupID.Equals(temp1.ParentGroupID));
                            temp1 = temp;
                        }
                        else
                        {
                            if (entities2.Find(s => s.GroupID.Equals(temp1.GroupID)) == null)
                            { entities2.Add(temp1); }
                            break;
                        }
                    }
                }
                return entities2.OrderBy(item => item.GroupLevel).ToList();
            }
            /// <summary>
            /// 数据绑定
            /// </summary>
            private void bind()
            {
                IList<CV_QM_DEFECT_LABEL_GROUP> entities = findparent();
                this.TreeView1.Nodes.Clear();
                foreach (CV_QM_DEFECT_LABEL_GROUP cv_qm_defect_label_group in entities)
                {
                    if (cv_qm_defect_label_group.ParentGroupID.HasValue)
                    {
                        TreeNode[] nodeArray = this.TreeView1.Nodes.Find(cv_qm_defect_label_group.ParentGroupID.Value.ToString(), true);
                        if ((nodeArray != null) && (nodeArray.Length > 0))
                        {
                            nodeArray[0].Nodes.Add(cv_qm_defect_label_group.GroupID.Value.ToString(), cv_qm_defect_label_group.GroupName, "Group.png", "Group.png");
                            nodeArray[0].Nodes[cv_qm_defect_label_group.GroupID.Value.ToString()].Tag = cv_qm_defect_label_group;
                        }
                        else
                        {
                            this.TreeView1.Nodes.Add(cv_qm_defect_label_group.GroupID.Value.ToString(), cv_qm_defect_label_group.GroupName, "Group.png", "Group.png");
                            this.TreeView1.Nodes[cv_qm_defect_label_group.GroupID.Value.ToString()].Tag = cv_qm_defect_label_group;
                        }
                    }
                    else
                    {
                        this.TreeView1.Nodes.Add(cv_qm_defect_label_group.GroupID.Value.ToString(), cv_qm_defect_label_group.GroupName, "Group.png", "Group.png");
                        this.TreeView1.Nodes[cv_qm_defect_label_group.GroupID.Value.ToString()].Tag = cv_qm_defect_label_group;
                    }
                }
                this.TreeView1.ExpandAll();
            }
    
        }
    }
    

      

  • 相关阅读:
    .net core2.0 中使用aspectcore实现aop
    [Superset] 设置Superset的登录设置
    [Python]Pandas对于非唯一的label index的数据选择问题
    Data Science Radar测试结果
    [R]R包版本更迭【持续更新】
    [面试] 删除多余的数组内容
    [Python]Python中的包(Package)
    [Linux] 使用Yum在CentOS上安装MySQL
    [pyMongo]insert_many的Bulkwrite实现机制
    [Git]2018-10 解决git cmd中文乱码问题
  • 原文地址:https://www.cnblogs.com/yueyan/p/11646857.html
Copyright © 2011-2022 走看看