zoukankan      html  css  js  c++  java
  • C# TreeView模糊查找节点

            List<TreeNode> listSearchTreeNodes;
            private void btn_Search_Click(object sender, EventArgs e)
            {
                if (string.IsNullOrEmpty(textBox1.Text.Trim()))
                { return;}
                listSearchTreeNodes = new List<TreeNode>();
                foreach (TreeNode node in Mange_TreeView.Nodes)  //Mange_TreeView是treeview控件名称
                {
                    SearchLayer(node, this.textBox1.Text.Trim());
                }
                for (int i = 0; i < listSearchTreeNodes.Count; i++)
                {
                    TreeNode trNode = listSearchTreeNodes[i];
                    ExpandNode(trNode);
                    if (i == 0 && trNode.Parent != null)
                    {
                        Mange_TreeView.SelectedNode = trNode.Parent;
                    }
                    trNode.BackColor = Color.Green;
                }
            }
    
            private void SearchLayer(TreeNode node, string name)
            {
                if (node.Nodes.Count != 0)
                {
                    for (int i = 0; i < node.Nodes.Count; i++)
                    {
                        SearchLayer(node.Nodes[i], name);
                    }
                }
                else if (string.Equals(node.Text, name) || node.Text.Contains(name))
                {
                    listSearchTreeNodes.Add(node);
                }
            }
            //展开节点
            private void ExpandNode(TreeNode node)
            {
                if (node.Parent != null)
                {
                    node.Expand();
                    ExpandNode(node.Parent);
                }
            }
  • 相关阅读:
    Codeforces Canda Cup 2016
    Codeforces Round #377(div 2)
    后缀数组专题
    Codeforces Round #375(div 2)
    Codeforces Round #374(div 2)
    [HDU5902]GCD is Funny(xjb搞)
    [HDU5904]LCIS(DP)
    HDU 1251统计难题
    POJ2104 K-TH NUMBER 传说中的主席树
    poj 3041
  • 原文地址:https://www.cnblogs.com/yc1224/p/11976537.html
Copyright © 2011-2022 走看看