TreeView没有填充节点

时间:2019-03-28 14:12:01

标签: c#

您能帮我解决一些问题吗?我试图用下面显示的代码填充treeview节点。

<div style = {{display :  'flex' , backgroundColor : '#333333'}}>

}

当我从 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace CheckBoxTest { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void checkBox1_CheckedChanged(object sender, EventArgs e) { LoadFoldersInTreeView(treeView1); } private void LoadFoldersInTreeView(TreeView treeName) { treeName.BeginUpdate(); treeName.Nodes.Add(@"D:\"); DirectoryInfo dirInfo = new DirectoryInfo(@"D:\Incomming"); TreeNode node = new TreeNode(); node.Text = "Files"; GetFolders(dirInfo, node); treeName.Nodes[0].Nodes.Add(node); treeName.Update(); } private void GetFolders(DirectoryInfo dirInfo, TreeNode node) { DirectoryInfo[] dInfo = dirInfo.GetDirectories(); if (dInfo.Length > 0) { TreeNode treeNode = new TreeNode(); foreach (DirectoryInfo driSub in dInfo) { treeNode = node.Nodes.Add(text: driSub.FullName); GetFolders(driSub, treeNode); } } } } 调用此过程时,TreeView已填充,但是当我从InitializeComponent();调用时,什么也没有发生。 但是我只有在检查项目时才需要填充这棵树。

0 个答案:

没有答案