gpt4 book ai didi

c# - "The type ' 系统.Windows.Forms.TreeNodeCollection ' has no constructors defined"

转载 作者:太空狗 更新时间:2023-10-30 00:27:25 27 4
gpt4 key购买 nike

我有这个代码:

    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);
}

this.treeCollection = new TreeNodeCollection(); 返回

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

如果我删除这一行,我会得到 treeCollection 从未被赋值并且永远为空...

Field 'Client.treeCollection' is never assigned to, and will always have its default value null

如何将 treeCollection 分配为新的 TreeNodeCollection,以便我可以使用我的 AddNode 方法向其添加节点?

最佳答案

TreeNodeCollection 有一个内部工厂或构造函数,因此它只能由 TreeView 控件使用。

但是……你不需要它。只需使用一个节点作为您的根节点。然后清除它的 child

rootNode.Nodes.Clear();

或者,如果必须,只需创建一个

List<TreeNode>

关于c# - "The type ' 系统.Windows.Forms.TreeNodeCollection ' has no constructors defined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6600041/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com