本文介绍了以递归方式将子节点添加到树中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨peeps ..


我使用来自IE COntrols的TreeView控件创建一个目录

结构,并尝试递归执行。


代码有效,但我的问题是如何让子目录显示为树中的叶子而不是新的分支?




这里是代码..


private void RecurseTree(DirectoryInfo theDir,int nLevel)

{

TreeNode libraryNode = null;

DirectoryInfo [] subFolders = theDir.GetDirectories();


//填充树

for(int i = 0; i< subFolders.Length; i ++)

{

libraryNode = new TreeNode();

libraryNode.Text = subFolders [i] .Name;

treeDocuments.Nodes.Add(libraryNode);

libraryNode = null;

RecurseTree(subFolders [i],nLevel + 1);

}

}


任何帮助表示赞赏!


干杯

Dan

解决方案



在树中出现






Hi peeps..

Im using the TreeView control from IE COntrols to create a directory
structure, and trying to do it recursively.

The code works, but my question is simply how can I make the subdirs appear
as leaves in the Tree, rather than as new branches?

Here''s the code..

private void RecurseTree(DirectoryInfo theDir, int nLevel)
{
TreeNode libraryNode = null;
DirectoryInfo[] subFolders = theDir.GetDirectories();

// populate the tree
for (int i=0; i < subFolders.Length; i++)
{
libraryNode = new TreeNode();
libraryNode.Text = subFolders[i].Name;
treeDocuments.Nodes.Add(libraryNode);
libraryNode = null;
RecurseTree(subFolders[i], nLevel+1);
}
}

Any help appreciated!

Cheers
Dan

解决方案




appear






这篇关于以递归方式将子节点添加到树中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 01:04