System.Windows.Forms.TreeNodeCollection.RemoveAt C# (CSharp) Method

RemoveAt() public method

public RemoveAt ( int index ) : void
index int
return void
        public virtual void RemoveAt(int index)
        {
            if (index < 0 || index >= Count)
                throw new ArgumentOutOfRangeException("index");

            items.RemoveAt(index);
            UpdateIndexes();

            if (owner.TreeView != null)
                owner.TreeView.Refresh();
        }

Usage Example

Example #1
0
 private void Flatten(TreeNodeCollection collection, bool shortify)
 {
     /* Recursion */
     foreach (TreeNode node in collection) {
         Flatten(node.Nodes, shortify);
     }
     /* Remove empty folders from the collection */
     for (int i = 0; i < collection.Count; i++) {
         if (collection[i].Tag == null && collection[i].Nodes.Count == 0) {
             collection.RemoveAt(i);
             i--;
         }
     }
     if (!shortify) {
         /* If only element is Route/Train/Library/SharedLibrary, then remove it */
         if (collection.Count == 1 && collection[0].Tag is RemoveIfPossibleAttribute) {
             TreeNodeCollection elements = collection[0].Nodes;
             collection.RemoveAt(0);
             foreach (TreeNode element in elements) {
                 collection.Add(element);
             }
         }
         /* Expand folders that only contain one element */
         if (collection.Count == 1) {
             if (collection[0].Nodes.Count != 0) {
                 collection[0].Expand();
             }
         }
     } else {
         /* Flatten out folders that contain only one element */
         if (collection.Count == 1 && collection[0].Tag == null) {
             TreeNodeCollection elements = collection[0].Nodes;
             collection.RemoveAt(0);
             foreach (TreeNode element in elements) {
                 collection.Add(element);
             }
         }
     }
 }
All Usage Examples Of System.Windows.Forms.TreeNodeCollection::RemoveAt