MS Treeview控件:防止树视图中出现重复的noed [英] MS Treeview control : Prevent duplicate noed in treeview
问题描述
您好,我有一个在VS 2010中设计的树视图控件。我有一个root,parent(我称之为一个组)和一个child(Standalone hyper v或Cluster hyper v)。对于集群部分,我只想显示一个集群和另一个子集(与集群关联的主机)。
但在我的代码中,我添加了与主机关联的时间相同的群集。
例子
集群1
-------- noed1
集群1
- ------- noed2
我只需要展示。
群集1
--------- noed1
--------- noed2
我设法不创建第二个集群noed如果存在,但现在我不能添加noed2,我不知道为什么。
我的代码是:
Hello , I have a treeview control designed in VS 2010 . I have a root , parent ( i call a group ) and child ( Standalone hyper v or Cluster hyper v) . For the cluster part i only want to display one cluster and another child (the host(s) associated with the cluster) .
But in my code , i am adding the same cluster noed as many time as the host associated .
Exemple
Cluster 1
--------noed1
Cluster 1
---------noed2
I only need to show.
Cluster 1
---------noed1
---------noed2
I manage to not create the second cluster noed if exist but now i can't add the noed2 , i dont know why .
My code is :
SysWeb.TreeNode Clusternoed = Clustergroup;
Clusternoed = new SysWeb.TreeNode(Children);
if (output != "found")
{
SysWin.MessageBox.Show("No cluster found for" + Children);
group.ChildNodes.Add(Clustergroup);//---------->add cluster is working
Clustergroup.ChildNodes.Add(Clusternoed); //---> add noed is working .
}
else
{
SysWin.MessageBox.Show("Cluster found for :" + Children);
//group.ChildNodes.Add(Clustergroup); dont add cluster but only children
Clustergroup.ChildNodes.Add(Clusternoed); //--> not working
}
如果我在其他情况下添加群集,它可以工作并添加noed2 到集群。但我不想两次拥有相同的群集名称。我需要显示如上所示..很多非常感谢你的帮助
If i add the cluster in else condition , it works and also add "noed2" to the cluster . But i dont wan t to have the same cluster name twice . I need to display as show above .. Many many thanks for your help
推荐答案
根据这个逻辑尝试一下。
Try something according to this logic.
// The method CheckIfClusterExist is your method and should return null if no cluster was found
TreeNode clusterFound = CheckIfClusterExist("ClusterName");
if (clusterFound == null)
{
clusterFound = group.ChildNodes.Add(Clustergroup);
}
clusterFound.ChildNodes.Add(Clusternoed);
这篇关于MS Treeview控件:防止树视图中出现重复的noed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!