Exemple #1
0
        public void FillTree()
        {
            var input = txtFilter.Text;
            var query = RedisHelper.Keys.AsQueryable();

            if (!string.IsNullOrEmpty(input))
            {
                query = query.Where(p => p.IndexOf(input, StringComparison.OrdinalIgnoreCase) > -1);
            }
            var list = query.OrderBy(p => p).ToList();

            TreeBuilder.FillTreeView(list, treeView1);
        }
        public static void FillTreeView(List <string> list, TreeView treeView1)
        {
            var         root = new TreeBuilder();
            TreeBuilder son;

            root.Depth    = 0;
            root.Index    = 0;
            root.Text     = "root";
            root.Children = new Dictionary <string, TreeBuilder>();

            foreach (string str in list)
            {
                string[] seperated = str.Split(':');
                son = root;
                int index = 0;
                for (int depth = 0; depth < seperated.Length; depth++)
                {
                    if (son.Children.ContainsKey(seperated[depth]))
                    {
                        son = son.Children[seperated[depth]];
                    }
                    else
                    {
                        son.Children.Add(seperated[depth], new TreeBuilder());
                        son       = son.Children[seperated[depth]];
                        son.Index = ++index;
                        son.Depth = depth + 1;
                        son.Text  = seperated[depth];
                        if (depth == seperated.Length - 1)
                        {
                            son.FullText = str;
                        }
                        son.Children = new Dictionary <string, TreeBuilder>();
                    }
                }
            }



            treeView1.Nodes.Clear();

            AddToTreeVeiw(treeView1.Nodes, root.Children);
            Expend(treeView1.Nodes);
        }