Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"The type 'System.Windows.Forms.TreeNodeCollection' has no constructors defined"

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?

like image 358
Danpe Avatar asked Dec 21 '22 11:12

Danpe


1 Answers

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>
like image 121
Neil N Avatar answered Dec 24 '22 02:12

Neil N