树视图中同名的精细节点 [英] fine node of same name in tree view

查看:87
本文介绍了树视图中同名的精细节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows c#应用程序中使用树状视图.
我现在有节点Node1,我在Node1处添加了子节点,但首先我想知道子节点的名称是否已经存在(如果没有的话),然后添加或删除.
我使用此代码:

I am using tree view in my window c# application.
I have node Node1 now i add child node at Node1 but first i want to know is same name of child node already there if not then add or remove.
I use this code:

 TreeNode[] treeCol = Node1.Nodes.Find(ti, true);//ti child which i want to add
if (treeCol.Length > 0)
 {
     //not add
 }
  else
 {
    //add
 }


循环总是进入其他部分我不知道的问题.
任何人都可以解决这个问题.


Loop always goes in to else part what problem i don''t know.
Can any one solve this.

推荐答案

我以前使用过TreeNodeCollection.Find,它始终对我有用-所以我能想到的最好的猜测是您创建节点时,尚未正确设置其节点的Name属性.检查您是否设置了名称,而不仅仅是文本-查找不会查看Text属性.

或者,在显示的Find方法调用上放置一个断点,然后查看ti和节点列表".
I have used TreeNodeCollection.Find before, and it always works for me - so the best guess I can come up with is that you haven''t set the Name property of your node correctly when you created it. Check you did set Name, and not just Text - Find does not look at the Text property.

Alternatively, put a breakpoint on the Find method call you show, and look at ti and the Nodes List.


bool repeatlivenode = false;
foreach(po.Nodes中的TreeNode tn)
{
如果(tn.Text == ti)//ti是我要添加的节点
{
repeatlivenode = true;
休息;
}
其他
{
repeatlivenode = false;
}
}
如果(repeatlivenode == false)
{
TreeNode po1 = po.Nodes.Add(ti);
}
bool repeatlivenode = false;
foreach (TreeNode tn in po.Nodes)
{
if (tn.Text == ti)//ti is node which i want to add
{
repeatlivenode = true;
break;
}
else
{
repeatlivenode = false;
}
}
if (repeatlivenode == false)
{
TreeNode po1 = po.Nodes.Add(ti);
}


这篇关于树视图中同名的精细节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆