Exemplo n.º 1
0
 /// <summary>
 /// Removes each node of the collection
 /// </summary>
 public new void Clear()
 {
     ReadWriteLock.AcquireWriterLock(-1);
     while (this.Count > 0)
     {
         this[0].Remove();
     }
     ReadWriteLock.ReleaseWriterLock();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Remove an item from the collection and the TreeListView
        /// </summary>
        /// <param name="item"></param>
        public virtual void Remove(TreeListViewItem item)
        {
            int index = -1;

            ReadWriteLock.AcquireWriterLock(-1);
            for (int i = 0; i < this.Count; i++)
            {
                if (this[i] == item)
                {
                    index = i;
                }
            }
            if (index > -1)
            {
                RemoveAt(index);
            }
            ReadWriteLock.ReleaseWriterLock();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds an item in the collection and in the TreeListView
        /// </summary>
        /// <param name="item"></param>
        /// <returns>Index of the item in the collection</returns>
        public virtual int Add(TreeListViewItem item)
        {
            int index = GetInsertCollectionIndex(item);

            if (index == -1)
            {
                return(-1);
            }
            if (Parent != null)
            {
                item.SetParent(Parent);
            }
            item.Items.Comparer = this.Comparer;
            ReadWriteLock.AcquireWriterLock(-1);
            int treelistviewindex = GetInsertTreeListViewIndex(item);

            // Insert in the ListView
            if (treelistviewindex > -1)
            {
                ListView           listview = (ListView)TreeListView;
                InsertListViewItem insert   = new InsertListViewItem(listview.Items.Insert);
                if (listview.InvokeRequired)
                {
                    listview.Invoke(insert, new object[] { treelistviewindex, (ListViewItem)item });
                }
                else
                {
                    listview.Items.Insert(treelistviewindex, (ListViewItem)item);
                }
                if (item.IsExpanded)
                {
                    item.Expand();
                }
                item.SetIndentation();
            }
            // Insert in this collection
            if (index > -1)
            {
                List.Insert(index, item);
            }
            ReadWriteLock.ReleaseWriterLock();
            return(index);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Remove an item from the collection and the TreeListView
        /// </summary>
        /// <param name="index"></param>
        public new void RemoveAt(int index)
        {
            ReadWriteLock.AcquireWriterLock(-1);
            TreeListViewItem item = this[index];

            if (this[index].Visible && this.TreeListView != null)
            {
                ListView           listview = (ListView)TreeListView;
                RemoveListViewItem remove   = new RemoveListViewItem(listview.Items.Remove);
                if (listview.InvokeRequired)
                {
                    listview.Invoke(remove, new Object[] { (ListViewItem)item });
                }
                else
                {
                    listview.Items.Remove((ListViewItem)item);
                }
            }
            List.RemoveAt(index);
            item.SetParent(null);
            ReadWriteLock.ReleaseWriterLock();
        }
Exemplo n.º 5
0
 /// <summary>
 /// Sort the items in this collection (recursively or not)
 /// </summary>
 /// <param name="recursively">Recursively</param>
 public void Sort(bool recursively)
 {
     ReadWriteLock.AcquireWriterLock(-1);
     // Gets an array of the items
     TreeListViewItem[] thisarray = Array;
     //      System.Array.Sort(thisarray, new TreeListViewItemCollectionComparer(order));
     // Removes the items
     this.Clear();
     // Adds the items
     foreach (TreeListViewItem item in thisarray)
     {
         this.Add(item);
     }
     if (recursively)
     {
         foreach (TreeListViewItem item in thisarray)
         {
             item.Items.Sort(true);
         }
     }
     ReadWriteLock.ReleaseWriterLock();
 }