internal void RemoveAtInternal(int index) { if (TreeListView != null) { if (TreeListView.InvokeRequired) { throw new Exception("Invoke required"); } } TreeListViewItem item = this[index]; if (this[index].Visible && this.TreeListView != null) { item.Hide(); } List.RemoveAt(index); item.SetParent(null); // Redraw parent if no more children if (Count == 0 && TreeListView != null && Parent != null) { Parent.Redraw(); } // Redraw new last item if (Count > 0 && TreeListView != null && index == Count) { this[index - 1].Redraw(); } OnItemRemoved(new TreeListViewEventArgs(item, TreeListViewAction.Unknown)); }
public virtual int Add(TreeListViewItem item) { if (TreeListView != null) { if (TreeListView.InvokeRequired) { throw (new Exception("Invoke required")); } } // Do not add the item if the collection owns a TreeListView recursively // and the item already owns a TreeListView if (TreeListView != null && item.ListView != null) { throw new Exception("The Item is already in a TreeListView"); } int index = GetInsertCollectionIndex(item); if (index == -1) { return(-1); } if (Parent != null) { item.SetParent(Parent); } item.Items.Comparer = this.Comparer; int treeListViewIndex = GetInsertTreeListViewIndex(item, index); // Insert in the ListView if (treeListViewIndex > -1) { ListView listview = (ListView)TreeListView; listview.Items.Insert(treeListViewIndex, (ListViewItem)item); if (item.IsExpanded) { item.Expand(); } item.SetIndentation(); } // Insert in this collection if (index > -1) { List.Insert(index, item); } if (index > -1) { OnItemAdded(new TreeListViewEventArgs(item, TreeListViewAction.Unknown)); } if (Count == 1 && TreeListView != null && Parent != null) { if (Parent.Visible) { Parent.Redraw(); } } return(index); }