コード例 #1
0
 /// <summary>
 /// Expand
 /// </summary>
 public void Expand()
 {
     // 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 (this.Visible)
     {
         Items.ReadWriteLock.AcquireReaderLock(-1);
         for (int i = Items.Count - 1; i >= 0; i--)
         {
             TreeListViewItem item = this.Items[i];
             if (!item.Visible)
             {
                 ListView LView = this.ListView;
                 LView.Items.Insert(
                     this.Index + 1,
                     item);
                 item.SetIndentation();
             }
             if (item.IsExpanded)
             {
                 item.Expand();
             }
         }
         Items.ReadWriteLock.ReleaseReaderLock();
     }
     // The item wasn't expanded -> raise an event
     if (Visible && !_isexpanded && ListView != null)
     {
         this._isexpanded = true;
         TreeListViewEventArgs e = new TreeListViewEventArgs(
             this, TreeListViewAction.Expand);
         ListView.RaiseAfterExpand(e);
         if (AfterExpand != null)
         {
             AfterExpand(this);
         }
     }
     this._isexpanded = true;
 }
コード例 #2
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);
        }