本文整理汇总了C#中System.Windows.Forms.TreeNodeCollection.RemoveAt方法的典型用法代码示例。如果您正苦于以下问题:C# TreeNodeCollection.RemoveAt方法的具体用法?C# TreeNodeCollection.RemoveAt怎么用?C# TreeNodeCollection.RemoveAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.TreeNodeCollection
的用法示例。
在下文中一共展示了TreeNodeCollection.RemoveAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Flatten
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);
}
}
}
}
示例2: RemoveUserFromList
/// <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;
}
示例3: Group
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);
}
}
示例4: Flatten
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);
}
}
}
示例5: FilterTreeView
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--);
}
}
}
}
示例6: loadGroup
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);
}
}
}
示例7: UpdateNode
/// <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;
}
示例8: Sort
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;
}
}
}
}
}
示例9: merge_nodes
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 );
}
示例10: RemoveItem
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;
}
}
}
}
}
示例11: AddAndRemoveFolderNodes
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);
}
}
}
示例12: RemoveTreeNodesForRemovedReferenceFileSavesIn
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
}
示例13: RemoveItem
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;
}
}
}
}
}
示例14: DelSelCmp
//---------------------------------------------------------------------------
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
}
示例15: RemoveAt
private void RemoveAt(TreeNodeCollection nodes, int index)
{
if (TestList.InvokeRequired == true)
{
this.Invoke(new RemoveNodeAtCB(RemoveAt), new object[] { nodes, index });
return;
}
nodes.RemoveAt(index);
}