public void RemoveNode(TreeNode TN) { ClearChildren(TN); if (items.Contains(TN)) { this.items.Remove(TN); } }
public void AddRootItem(TreeNode TN) { TN.Level = 0; TN.PropertyChanged +=new PropertyChangedEventHandler(TN_PropertyChanged); this.items.Add(TN); if (TN.IsExpanded) { PopulateChildren(TN); } }
public void UpdateChildren(TreeNode TN) { TN.UpdateChildren(); if (TN.HasChildren == false) { TN.IsExpanded = false; } else if (TN.IsExpanded) { if (items.Contains(TN)) { ClearChildren(TN); PopulateChildren(TN); } } }
private void ClearChildren(TreeNode TN) { if (items.Contains(TN)) { int indexToRemove = this.items.IndexOf(TN) + 1; while ((indexToRemove < this.items.Count) && (this.items[indexToRemove].Level > TN.Level)) { items[indexToRemove].PropertyChanged -= new PropertyChangedEventHandler(TN_PropertyChanged); items.RemoveAt(indexToRemove); } } }
public NodeExpandedChanagedEventArgs(TreeNode tN) { _tN = tN; }
private void PopulateChildren(TreeNode TN) { if (items.Contains(TN)) { int index = this.items.IndexOf(TN); if (index == this.items.Count - 1 || this.items[index + 1].Level <= TN.Level) { IEnumerable myList = TN.Children; int offset = 0; foreach (TreeNode TN2 in myList) { TN2.PropertyChanged += new PropertyChangedEventHandler(TN_PropertyChanged); TN2.Level = TN.Level + 1; this.items.Insert(index + offset + 1, TN2); offset++; } foreach (TreeNode TN2 in myList) { if ((TN2.IsExpanded) && (TN.HasChildren)) { PopulateChildren(TN2); } } } } }