I have this code:
private TreeNodeCollection treeCollection;
public Client(TcpClient c)
{
this.tcpClient = c;
this.tree = null;
this.treeCollection = new TreeNodeCollection();
this.treeCollection.Clear();
}
public void AddNode(string node)
{
this.treeCollection.Add(node);
}
the this.treeCollection = new TreeNodeCollection();
returns
The type 'System.Windows.Forms.TreeNodeCollection' has no constructors defined
And if im deleting the this row i get that treeCollection is never assigned and will always be null...
Field 'Client.treeCollection' is never assigned to, and will always have its default value null
How can i assign the treeCollection as a new TreeNodeCollection so i can add nodes to it using my AddNode method?
TreeNodeCollection has an internal factory or constructor, so it can only be used by the TreeView control.
But... you don't need it. Just use a single node as your root node. Then clear its children with
rootNode.Nodes.Clear();
Or if you must, just create a
List<TreeNode>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With