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); }
public bool IsAParentOf(TreeListViewItem item) { TreeListViewItem[] parents = item.ParentsInHierarch; foreach (TreeListViewItem parent in parents) { if (parent == this) { return(true); } } return(false); }
public virtual void Remove(TreeListViewItem item) { TreeListView treelistview = this.TreeListView; if (treelistview != null) { treelistview.BeginUpdate(); } RemoveInternal(item); if (treelistview != null) { treelistview.EndUpdate(); } }
internal void RemoveInternal(TreeListViewItem item) { if (TreeListView != null) { if (TreeListView.InvokeRequired) { throw (new Exception("Invoke required")); } } int index = GetIndexOf(item); if (index == -1) { return; } RemoveAtInternal(index); }
public TreeListViewItem[] ToArray() { if (TreeListView != null) { if (TreeListView.InvokeRequired) { throw new Exception("Invoke required"); } } int size = this.Count; TreeListViewItem[] items = new TreeListViewItem[size]; for (int i = 0; i < size; i++) { items[i] = this[i]; } return(items); }
private int GetInsertCollectionIndex(TreeListViewItem item) { if (TreeListView != null) { if (TreeListView.InvokeRequired) { throw (new Exception("Invoke required")); } } int index = -1; if (!_Sortable) { index = Count; } else if (!Contains(item) && !ListViewContains(item)) { switch (SortOrder) { // No sortorder -> at the end of the collection case System.Windows.Forms.SortOrder.None: index = this.Count; break; default: for (int i = 0; i < this.Count; i++) { // Change the index for the compare if the order is descending int indexcompare = i; int comp = Comparer.Compare(item, this[indexcompare]); if (comp <= 0) { index = indexcompare; break; } } index = index == -1 ? this.Count : index; break; } } return(index); }
public int GetIndexOf(TreeListViewItem item) { if (TreeListView != null) { if (TreeListView.InvokeRequired) { throw new Exception("Invoke required"); } } int index = -1; for (int i = 0; i < this.Count; i++) { if (this[i] == item) { index = i; break; } } return(index); }
public virtual bool Contains(TreeListViewItem item) { if (TreeListView != null) { if (TreeListView.InvokeRequired) { throw (new Exception("Invoke required")); } } bool founded = false; foreach (TreeListViewItem elt in this) { if (item == elt) { founded = true; break; } } return(founded); }
public int Compare(object x, object y) { TreeListViewItem a = (TreeListViewItem)x; TreeListViewItem b = (TreeListViewItem)y; int result = 1; if (Column < a.SubItems.Count && Column < b.SubItems.Count) { result = string.CompareOrdinal(a.SubItems[Column].Text.ToUpper(), b.SubItems[Column].Text.ToUpper()); } switch (SortOrder) { case SortOrder.Ascending: return(result); case SortOrder.Descending: return(-result); default: return(1); } }
private int GetInsertTreeListViewIndex(TreeListViewItem item, int collectionindex) { if (TreeListView == null) { return(-1); } if (TreeListView != null) { if (TreeListView.InvokeRequired) { throw (new Exception("Invoke required")); } } if (Owner != null) { int a = 0; a++; } int index = -1; // First level item (no parent) if (Owner != null && collectionindex != -1) { index = collectionindex == 0 ? 0 : this[collectionindex - 1].LastChildIndexInListView + 1; } else if (Parent != null && collectionindex != -1) { if (!Parent.Visible || !Parent.IsExpanded) { index = -1; } else { index = collectionindex == 0 ? Parent.Index + 1 : Parent.Items[collectionindex - 1].LastChildIndexInListView + 1; } } return(index); }
public TreeListViewEventArgs(TreeListViewItem item, TreeListViewAction action) { _Item = item; _Action = action; }
internal void SetParent(TreeListViewItem parent) { _Parent = parent; }
internal void ExpandInternal() { if (IsInATreeListView) { if (ListView.InvokeRequired) { throw new Exception("Invoke Required"); } } TreeListViewItem selItem = null; if (TreeListView != null) { selItem = TreeListView.FocusedItem; } // Must set ListView.checkDirection to CheckDirection.None. // Forbid recursively checking. CheckDirection oldDirection = CheckDirection.All; if (ListView != null) { oldDirection = this.ListView.CheckDirection; ListView.CheckDirection = CheckDirection.None; } // The item wasn't expanded -> raise an event if (Visible && !_IsExpanded && ListView != null) { TreeListViewCancelEventArgs e = new TreeListViewCancelEventArgs(this, TreeListViewAction.Expand); ListView.RaiseBeforeExpand(e); if (e.Cancel) { return; } } if (Visible) { for (int i = Items.Count - 1; i >= 0; i--) { TreeListViewItem item = this.Items[i]; if (!item.Visible) { ListView listView = this.ListView; listView.Items.Insert(this.Index + 1, item); item.SetIndentation(); } if (item.IsExpanded) { item.Expand(); } } } // The item wasn't expanded -> raise an event if (Visible && !_IsExpanded && IsInATreeListView) { this._IsExpanded = true; TreeListViewEventArgs e = new TreeListViewEventArgs(this, TreeListViewAction.Expand); ListView.RaiseAfterExpand(e); if (AfterExpand != null) { AfterExpand(this); } } this._IsExpanded = true; // Reset ListView.checkDirection if (IsInATreeListView) { ListView.CheckDirection = oldDirection; } if (TreeListView != null && selItem != null) { if (selItem.Visible) { selItem.Focused = true; } } }
public TreeListViewItemCollection(TreeListViewItem parent) { _Parent = parent; }
internal void CollapseInternal() { if (IsInATreeListView) { if (ListView.InvokeRequired) { throw new Exception("Invoke Required"); } } TreeListViewItem selItem = null; if (TreeListView != null) { selItem = TreeListView.FocusedItem; } // The item was expanded -> raise an event if (Visible && _IsExpanded && ListView != null) { TreeListViewCancelEventArgs e = new TreeListViewCancelEventArgs(this, TreeListViewAction.Collapse); ListView.RaiseBeforeCollapse(e); if (e.Cancel) { return; } } // Collapse if (this.Visible) { foreach (TreeListViewItem item in Items) { item.Hide(); } } // The item was expanded -> raise an event if (Visible && _IsExpanded && IsInATreeListView) { this._IsExpanded = false; TreeListViewEventArgs e = new TreeListViewEventArgs(this, TreeListViewAction.Collapse); ListView.RaiseAfterCollapse(e); if (AfterCollapse != null) { AfterCollapse(this); } } this._IsExpanded = false; if (IsInATreeListView && selItem != null) { if (selItem.Visible) { selItem.Focused = true; } else { ListView listview = (ListView)TreeListView; listview.SelectedItems.Clear(); TreeListViewItem[] items = selItem.ParentsInHierarch; for (int i = items.Length - 1; i >= 0; i--) { if (items[i].Visible) { items[i].Focused = true; break; } } } } }
public bool Contains(TreeListViewItem item) { return(base.Contains((ListViewItem)item)); }
public int IndexOf(TreeListViewItem item) { return(base.IndexOf((ListViewItem)item)); }
public TreeListViewBeforeLabelEditEventArgs(TreeListViewItem item, int column, string label) : base(item, column, label) { }
public TreeListViewCancelEventArgs(TreeListViewItem item, TreeListViewAction action) : base(item, action) { }