Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 

                                }


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
Posted
Comments
George Jonsson 19-Sep-14 5:54am    
What is the error you get?
This code is a bit weird also.
SysWeb.TreeNode Clusternoed = Clustergroup;
Clusternoed = new SysWeb.TreeNode(Children);
You overwrite the value of Clusternoed in the second line which makes the first line useless.
Seevadassen KARUPPANNAN 19-Sep-14 6:04am    
i am not getting any error . the output=found is a search if i find the cluster in all nodes , the output variable = found else i dont find the cluster the i need to create the cluster noed . with the line 'Group.ChildNodes.Add(Clustergroup)' and add the child 'Clustergroup.ChildNodes.Add(Clusternoed)'. I again search , If find the same cluster so i dont have to create it but only add the child 'Clustergroup.ChildNodes.Add(Clusternoed)';

I have not copy the whole code . I am filling the treeview with sql commands , so i have to verify for a cluster exist or not ( if yes i only add host belonging to it else i create it and the add all host(s) that belong to it.
Seevadassen KARUPPANNAN 19-Sep-14 5:59am    
i am not getting any error . the output=found is a search if i find the cluster in all nodes , the output variable = found else i dont find the cluster the i need to create the cluster noed . with the line 'Group.ChildNodes.Add(Clustergroup)' and add the child 'Clustergroup.ChildNodes.Add(Clusternoed)'. I again search , If find the same cluster so i dont have to create it but only add the child 'Clustergroup.ChildNodes.Add(Clusternoed)';
Seevadassen KARUPPANNAN 19-Sep-14 6:02am    
I have not copy the whole code . I am filling the treeview with sql commands , so i have to verify for a cluster exist or not ( if yes i only add host belonging to it else i create it and the add all host(s) that belong to it.
Seevadassen KARUPPANNAN 19-Sep-14 6:06am    
Is inserting the child at the cluster(index) a solution ? I get the Cluster1.index and add the child using addat to the existing cluster1 ?

1 solution

Try something according to this logic.

C#
// 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);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900