查找树视图子名称 [英] Find tree view child name
问题描述
我在c#的窗口应用程序中使用树状视图.
我的Root未命名为Hart,它的子级是Serial,而serial的子级是COM.
COM上有很多子节点.
我希望所有COM的子名称都在一个数组中,我会在运行时动态添加子名称.
我想搜索COM子节点,并且如果子节点已经具有要添加的同名名称,那么如果不想添加,则不想添加.
我使用此代码:
I use tree view in my window application in c#.
I have Root not named Hart and it''s child is serial and serial''s child is COM.
and there is many child node at COM.
I want all COM''s child name in one array i add child dynamically at run time.
I want to search COM child node and if child is already with same name which i want to add then don''t want to add if not then add.
I use this code:
TreeNode[] treeCol = COM.Nodes.Find(no.ToString(), true);
if (treeCol.Length > 0)
{
Not add....
}
else
{
TreeNode po1 = COM.Nodes.Add(no.ToString());
}
这段代码添加了重复子代,因此这将无法按我的意愿工作.
[edit]添加了代码块,将我的内容作为纯文本..."选项已禁用-OriginalGriff [/edit]
This code add repeat child so this will not work as i want.
[edit]Code block added, "Treat my content as plain text..." option disabled - OriginalGriff[/edit]
推荐答案
我认为不返回节点名称或文本.尝试使用编号名称.
您必须使用TreeNode.Add(key, text)
添加节点,否则Node.Name
为空
I thinkTreeNode.ToString()
does not return the node Name or Text. Try using no.Name.
You must add nodes usingTreeNode.Add(key, text)
, otherwiseNode.Name
is empty
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屋!