RemoveAt() public méthode

public RemoveAt ( int index ) : void
index int
Résultat void
Exemple #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);
             }
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Removes a user from the user tree view.
        /// </summary>
        /// <param name="user">The user to remove.</param>
        /// <param name="nodes">The nodes to search within.</param>
        /// <returns>true on removal, false if the node was not found.</returns>
        private bool RemoveUserFromList(IRCUser user, TreeNodeCollection nodes)
        {
            for (int i = 0; i < nodes.Count; i++)
            {
                if ((nodes[i].Tag != null) && (nodes[i].Tag == user))
                {
                    nodes.RemoveAt(i);
                    return true;
                }
                else
                {
                    if (this.RemoveUserFromList(user, nodes[i].Nodes))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
Exemple #3
0
 private void Group(TreeNodeCollection collection)
 {
     /* Group folders that have same text */
     for (int i = 1; i < collection.Count; i++) {
         if (collection[i].Tag == null) {
             for (int j = 0; j < i; j++) {
                 if (collection[j].Tag == null) {
                     if (collection[i].Text == collection[j].Text) {
                         TreeNodeCollection elements = collection[i].Nodes;
                         collection.RemoveAt(i);
                         foreach (TreeNode node in elements) {
                             collection[j].Nodes.Add(node);
                         }
                         i--;
                         break;
                     }
                 }
             }
         }
     }
     /* Recursion */
     foreach (TreeNode node in collection) {
         Group(node.Nodes);
     }
 }
Exemple #4
0
 private void Flatten(TreeNodeCollection collection)
 {
     /* Recursion */
     foreach (TreeNode node in collection) {
         Flatten(node.Nodes);
     }
     /* Flatten out folders that contain only one element */
     for (int i = 0; i < collection.Count; i++) {
         if (collection[i].Nodes.Count == 1) {
             TreeNode element = collection[i].Nodes[0];
             collection.RemoveAt(i);
             collection.Add(element);
             i--;
         }
     }
     /* 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--;
         }
     }
     /* Flatten out the only element if it is a folder */
     if (collection.Count == 1 && collection[0].Tag == null) {
         TreeNodeCollection elements = collection[0].Nodes;
         collection.RemoveAt(0);
         foreach (TreeNode node in elements) {
             collection.Add(node);
         }
     }
 }
 private void FilterTreeView(string searchString, TreeNodeCollection nodes)
 {
     for (int i = 0; i < nodes.Count; ++i)
     {
         var node = nodes[i];
         if (node.Nodes.Count > 0)
         {
             FilterTreeView(searchString, node.Nodes);
         }
         else
         {
             var bhvType = node.Tag as Type;
             if (bhvType != null
                 && !Match(bhvType, searchString))
             {
                 nodes.RemoveAt(i--);
             }
         }
     }
 }
Exemple #6
0
        private async void loadGroup(TreeNodeCollection nodes, ServiceGroup group = null)
        {
            using (var channel = ChannelManager.CreateChannel())
            {
                try
                {
                    var serviceGroups = group != null
                        ? await taskPool.AddTask(channel.Service.GetServiceGroups(group.Id))
                        : await taskPool.AddTask(channel.Service.GetRootServiceGroups());

                    foreach (var g in serviceGroups)
                    {
                        var node = new TreeNode()
                        {
                            Text = g.ToString(),
                            Checked = g.IsActive,
                            Tag = g
                        };

                        node.Nodes.Add(new TreeNode("загрузка...") { Tag = g });
                        nodes.Add(node);
                    }

                    var services = group != null
                        ? await taskPool.AddTask(channel.Service.GetServices(group.Id))
                        : await taskPool.AddTask(channel.Service.GetRootServices());

                    foreach (var s in services)
                    {
                        var node = new TreeNode()
                        {
                            Text = s.ToString(),
                            Checked = s.IsActive,
                            Tag = s
                        };
                        nodes.Add(node);
                    }

                    if (group != null)
                    {
                        nodes.RemoveAt(0);
                    }
                }
                catch (OperationCanceledException) { }
                catch (CommunicationObjectAbortedException) { }
                catch (ObjectDisposedException) { }
                catch (InvalidOperationException) { }
                catch (FaultException exception)
                {
                    UIHelper.Warning(exception.Reason.ToString());
                }
                catch (Exception exception)
                {
                    UIHelper.Warning(exception.Message);
                }
            }
        }
 /// <summary>
 /// Add/Change a node
 /// </summary>
 /// <param name="aNodes">Nodes for this one to join</param>
 /// <param name="aFolder">Folder to use</param>
 /// <param name="aChecked">Checked or not</param>
 /// <returns>The new node</returns>
 private TreeNode UpdateNode(TreeNodeCollection aNodes, string aFolder, bool aChecked)
 {
     if (aNodes.Count > 0 && string.IsNullOrEmpty(aNodes[0].Text)) aNodes.RemoveAt(0); // Remove the fake
     TreeNode NewNode = null;
     if (NodesByPath.ContainsKey(aFolder))
         NewNode = NodesByPath[aFolder]; // We already got one...
     else
         NewNode =
         aNodes[
             aNodes.Add(new TreeNode(NodeName( aFolder ))
                 {
                     Tag = aFolder,
                     Checked = aChecked,
                     SelectedImageIndex = aChecked ? 2 : 0,
                     ImageIndex = aChecked ? 2 : 0,
                 })];
     NodesByPath[aFolder] = NewNode;
     Exception HasErrs;
     bool HasSubs = GetDirectories(aFolder, out HasErrs).Length > 0;
     if (HasErrs != null)
     {
         NewNode.Tag = null;
         NewNode.ForeColor = Color.DarkGray;
         NewNode.ToolTipText = HasErrs.Message;
     }
     // Add a fake node so that the little '+' will show
     if (HasSubs)
         NewNode.Nodes.Add(string.Empty);
     return NewNode;
 }
        private void Sort(TreeNodeCollection treeNodeCollection)
        {
            int lastObjectExclusive = treeNodeCollection.Count;
            int whereObjectBelongs;
            for (int i = 0 + 1; i < lastObjectExclusive; i++)
            {
                if (StateTreeNodeExtensionMethods.Compare(treeNodeCollection[i], treeNodeCollection[i - 1]) < 0)
                {
                    if (i == 1)
                    {
                        TreeNode treeNode = treeNodeCollection[i];
                        treeNodeCollection.RemoveAt(i);

                        treeNodeCollection.Insert(0, treeNode);
                        continue;
                    }

                    for (whereObjectBelongs = i - 2; whereObjectBelongs > -1; whereObjectBelongs--)
                    {
                        if (StateTreeNodeExtensionMethods.Compare(treeNodeCollection[i], treeNodeCollection[whereObjectBelongs]) >= 0)
                        {
                            TreeNode treeNode = treeNodeCollection[i];

                            treeNodeCollection.RemoveAt(i);
                            treeNodeCollection.Insert(whereObjectBelongs + 1, treeNode);
                            break;
                        }
                        else if (whereObjectBelongs == 0 && 
                            StateTreeNodeExtensionMethods.Compare(treeNodeCollection[i], treeNodeCollection[0]) < 0)
                        {
                            TreeNode treeNode = treeNodeCollection[i];
                            treeNodeCollection.RemoveAt(i);
                            treeNodeCollection.Insert(0, treeNode);
                            break;
                        }
                    }
                }
            }
        }
Exemple #9
0
 void merge_nodes( TreeNodeCollection nodes, ArrayList l, int param )
 {
     for( int i = 0; i < nodes.Count; i++ ) {
         TreeNode tn = nodes[i];
         NodeTag obj = tn.Tag as NodeTag;
         if( obj == null )
             continue;
         int ind = l.IndexOf( obj.n );
         if( ind == -1 ) {
             nodes.RemoveAt( i );
             i--;
         } else {
             l.RemoveAt( ind );
         }
     }
     add_nodes( nodes, l, param );
 }
Exemple #10
0
        private void RemoveItem(TreeNodeCollection lst, BaseObject obj)
        {
            LoadTreeNodeChilds();

            if (obj is DisksDB.DataBase.Image)
            {
                DisksDB.DataBase.Image img = (DisksDB.DataBase.Image)obj;

                for (int i = 0; i < lst.Count; i++)
                {
                    if (lst[i] is TreeNodeImage)
                    {
                        TreeNodeImage ti = (TreeNodeImage)lst[i];

                        if (ti.InternalImage == img)
                        {
                            lst.RemoveAt(i);
                            return;
                        }
                    }
                }
            }
        }
        private void AddAndRemoveFolderNodes(string currentDirectory, TreeNodeCollection nodesToAddTo)
        {
            // todo: removes
            var directories = Directory.EnumerateDirectories(currentDirectory);

            foreach (string directory in directories)
            {
                TreeNode existingTreeNode = GetTreeNodeFor(directory);

                if (existingTreeNode == null)
                {
                    existingTreeNode = nodesToAddTo.Add(FileManager.RemovePath(directory));
                    existingTreeNode.ImageIndex = FolderImageIndex;
                }
                AddAndRemoveFolderNodes(directory, existingTreeNode.Nodes);
            }

            for(int i = nodesToAddTo.Count - 1; i > -1; i--)
            {
                TreeNode node = nodesToAddTo[i];

                bool found = false;

                foreach (string directory in directories)
                {
                    string directoryStripped = FileManager.RemovePath(directory);

                    if (directoryStripped.Equals(node.Text, StringComparison.OrdinalIgnoreCase))
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    nodesToAddTo.RemoveAt(i);
                }               
            }
        }
        private void RemoveTreeNodesForRemovedReferenceFileSavesIn(TreeNodeCollection treeNodeCollection, List<ReferencedFileSave> referencedFiles, IElement container)
        {
            #region Remove existing nodes if the ReferencedFileSave is gone

            for (int i = treeNodeCollection.Count - 1; i > -1; i--)
            {
                ReferencedFileSave referencedFileSave = treeNodeCollection[i].Tag as ReferencedFileSave;

                if (treeNodeCollection[i].IsFolderInFilesContainerNode())
                {
                    RemoveTreeNodesForRemovedReferenceFileSavesIn(treeNodeCollection[i].Nodes, referencedFiles, container);
                }
                else if (ShouldTreeNodeBeRemoved(treeNodeCollection, referencedFiles, i, referencedFileSave, container))
                {
                    treeNodeCollection.RemoveAt(i);
                }
            }
            #endregion
        }
Exemple #13
0
        private void RemoveItem(TreeNodeCollection lst, BaseObject obj)
        {
            LoadTreeNodeChilds();

            if (obj is DataBase.Category)
            {
                DataBase.Category c = (DataBase.Category) obj;

                for (int i = 0; i < lst.Count; i++)
                {
                    if (lst[i] is TreeNodeCategory)
                    {
                        TreeNodeCategory cc = (TreeNodeCategory) lst[i];

                        if (cc.cat == c)
                        {
                            lst.RemoveAt(i);
                            return;
                        }
                    }
                }
            }
            else if (obj is DataBase.Box)
            {
                DataBase.Box b = (DataBase.Box) obj;

                for (int i = 0; i < lst.Count; i++)
                {
                    if (lst[i] is TreeNodeBox)
                    {
                        TreeNodeBox bb = (TreeNodeBox) lst[i];

                        if (bb.InternalBox == b)
                        {
                            lst.Remove(bb);
                            return;
                        }
                    }
                }
            }
        }
		//---------------------------------------------------------------------------
		private void DelSelCmp(TreeNodeCollection Nodes){
			if ( Nodes == null) { return; }
			int i = 0;
			while (i < Nodes.Count){

				DelSelCmp(Nodes[i].Nodes);

				if ( ((MyTreeNode)Nodes[i]).MySelected ){
					if (  ((MyTreeNode)Nodes[i]).obj is System.Web.UI.Control ){
					}else{
						IComponent cmp = (IComponent)(((MyTreeNode)Nodes[i]).obj);
						if (cmp.Site != null){
							if (cmp.Site.Container != null){
								cmp.Site.Container.Remove(cmp);
								cmp.Dispose();
							}
						}
					}
					Nodes.RemoveAt(i);
				}else{
					i++;
				}
			}//while
		}
Exemple #15
0
 private void RemoveAt(TreeNodeCollection nodes, int index)
 {
     if (TestList.InvokeRequired == true)
     {
         this.Invoke(new RemoveNodeAtCB(RemoveAt), new object[] { nodes, index });
         return;
     }
     nodes.RemoveAt(index);
 }
Exemple #16
0
        private void RemoveItem(TreeNodeCollection lst, BaseObject obj)
        {
            LoadTreeNodeChilds();

            if (obj is DisksDB.DataBase.Disk)
            {
                DisksDB.DataBase.Disk d = (DisksDB.DataBase.Disk)obj;

                for (int i = 0; i < lst.Count; i++)
                {
                    if (lst[i] is TreeNodeDisk)
                    {
                        TreeNodeDisk dd = (TreeNodeDisk)lst[i];

                        if (dd.InternalDisk == d)
                        {
                            lst.RemoveAt(i);
                            return;
                        }
                    }
                }
            }
        }