作者jiing24 (jiing)
看板C_Sharp
标题[问题] 请问在TreeView中,如何判断是否已经存在某名称的节点?
时间Wed Apr 25 12:24:01 2007
目的:将资料库的节点资料,动态生成树状图
问题:请问在TreeView中,如何判断是否已经存在某名称的节点?
比如说我有个Root:net:good:morning 的节点
还有个: Root:net:good:afternoon 的节点
但是我在TreeView中画出的图形,应该是只有最後的morning和afternoon是二个叶节点,其它是同一个支干
目前试了很多方法都失败
例如:
TreeNode rootNode = new TreeNode();
rootNode.text= "net";
rootNode.value ="net";
利用下面二个方式来作判别都失败
treeView.nodes.contains(rootNode)
//这个说要valuePath,不是很懂
treeView.FindNode(rootNode.valuePath)
以下是目前的错误程式码片段:
string nodeOfTreeView = path[depth];
if ( nodeOfTreeView != null)
{
if (depth == 0)
{
rootNode.Text = nodeOfTreeView;
rootNode.Value = nodeOfTreeView;
rootNode.NavigateUrl = @"./ShowComponentDetails.aspx?Name=" + nodeOfTreeView;
if (TreeViewOfPath.FindNode(rootNode.ValuePath) != null)
{
// Indicate that the node was found.
showMsg("The specified node (" + rootNode.ValuePath + ") was found.");
}
else
{
// Indicate that the node is not in the TreeView control.
showMsg("The specified node (" + nodeOfTreeView + ") is not in this TreeView control.");
showMsg("new rootNode =" + rootNode.Value);
TreeViewOfPath.Nodes.Add(rootNode);
}
...
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 211.77.241.1
1F:→ jiing24:我有节点的名称,能否判断treeview中是否有相同名称的节点 04/25 19:32