Exemplo n.º 1
0
        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));
        }
Exemplo n.º 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)
        {
            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);
        }
 /// <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)
 {
     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);
 }