コード例 #1
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);
        }
コード例 #2
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();
        }