递归地将子节点添加到 TreeView C#

问题描述

我不认为这会很难做到,但在过去的 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 (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...