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

      

  • 相关阅读:
    一、编程语言
    1、计算机基础
    四、格式化输出与基本运算符
    二、变量及用户与程序互交
    三、基本数据类型
    查看静态库中有哪些函数
    vs2010 error MSB6006: “cmd.exe”已退出,代码为 1
    ffmpeg formats
    C#启动一个外部程序(3)CreateProcess
    C#启动一个外部程序(2)ShellExecute
  • 原文地址:https://www.cnblogs.com/yueyan/p/11646857.html
Copyright © 2011-2022 走看看