當我嘗試使用WinForms創建樹視圖時,出現堆棧溢出。創建TreeView時堆棧溢出
private void createFeatureTree()
{
FeatureTree.Nodes.Clear();
FeatureTree.Nodes.Add(createTreeNode(new DirectoryInfo(starting directory path)));
}
private TreeNode createTreeNode(DirectoryInfo directory)
{
var directoryNode = new TreeNode(directory.Name);
foreach (var dir in directory.GetDirectories())
{
directoryNode.Nodes.Add(createTreeNode(directory));
}
foreach (var file in directory.GetFiles())
{
directoryNode.Nodes.Add(new TreeNode(file.Name));
}
return directoryNode;
}
createFeatureTree()
在啓動時在其自己的線程上調用。我如何得到堆棧溢出錯誤? TreeView可以存儲的節點數量是否有限制?
我想你的意思是'directoryNode.Nodes.Add(createTreeNode(** dir **));' –