TreeNode Collection

  • Thread starter Thread starter juli jul
  • Start date Start date
J

juli jul

Hello,
I am trying to create a TreeNodeCollection and to attach it to a tree
view. How exactly can I do it?
I am trying to do:
TreeNodeCollection tnc=new TreeNodeCollection(node);
but keep getting errors.
How can I do it?
Thank you!
 
Hi Juli,

The basic procedure of adding nodes to an existing collection is like this:

TreeNode newNode = new TreeNode(someName);
this.TreeViewControl.Nodes.Add(newNode);

Is this what you are trying to do? Also, please post the code so that we
have a better idea.

HTH,
Rakesh Rajan
 
The TreeNodeCollection class does not have a public constructor. It is
created by the TreeView class.

To create a new collection of TreeNodes for a TreeView, first create an
array of TreeNodes, next, call Nodes.Clear() on the TreeView, then use
Nodes.AddRange() to add your array of TreeNodes.

Dale Preston
MCAD, MCDBA, MCSE
 
Hello,
I have a function that expects to get this argument:TreeNodeCollection
parentnode
I was trying to create it without the public constractor that is not
avalible but I didn't seccess in it:

TreeNode tn=new TreeNode("aaa");
al.Add(tn);
this.treeView1.Nodes.Clear();
this.treeView1.Nodes.AddRange(al);

I get compilation error.
How can I create an instance of a TreeNodeCollection?
Thanks you very much
 
Pass the Nodes property of your TreeView to your method:

myFunction(myTreeView.Nodes);

Or change your method to accept an array of TreeNodes.

Dale Preston
 
Thanks but I need to add xml elements to a tree view and this is done by
the function which gets the following arguments:
private void FillTree(XmlNode node, TreeNodeCollection parentnode)
But it's not working if I pass the collection in this way.Could you
tell me how to do it?
Thanks!
 
Hello,here is the line :
this.FillTree(oXmlDoc.DocumentElement,this.treeView1.Nodes);
but what I need is from some node to other and not all the xml doc ,how
can I do that?
Thanks in advance!
 
Back
Top