问题描述
我不认为这会很难做到,但在过去的 45 分钟左右我一直坚持这个。我正在尝试创建一个递归函数,该函数在目录中查找文件并将它们添加到 TreeView。 到目前为止,这是我的方法:
private void RecursiveAddToTree(string path,TreeNode parent)
{
var directories = Directory.GetDirectories(path);
var files = Directory.GetFiles(path);
foreach (var directory in directories)
{
var node = new TreeNode(getItemOrDirectoryName(directory)) {ImageIndex = 0,SelectedImageIndex = 1};
//this is where I need to add the child node to the parent node
RecursiveAddToTree(directory,node);
}
foreach (var file in files)
{
var node = new TreeNode(getItemOrDirectoryName(file)) {ImageIndex = 0,SelectedImageIndex = 0};
//this is where I need to add the child node to the parent node
}
}
我正在寻找一种方法,可以在给定父节点的情况下将子节点添加到父节点,但我似乎不知道该怎么做。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)