Ejemplo n.º 1
0
        private void PopulateChildren(ITreeNode item)
        {
            if (items.Contains(item))
            {
                int index = this.items.IndexOf(item);
                // если это последний в списке или уровень следующего не больше
                if (index == this.items.Count - 1 || this.items[index + 1].Level <= item.Level)
                {
                    IEnumerable children = item.Children;
                    if (children == null)
                    {
                        return;
                    }
                    int offset = 0;
                    foreach (ITreeNode child in children)
                    {
                        child.PropertyChanged += new PropertyChangedEventHandler(TN_PropertyChanged);
                        child.Level            = item.Level + 1;
                        this.items.Insert(index + offset + 1, child);

                        offset++;
                    }

                    foreach (ITreeNode child in children)
                    {
                        if ((child.IsExpanded) && (item.HasChildren))
                        {
                            PopulateChildren(child);
                        }
                    }
                }
            }
        }