标签:ext cto eve node public TreeView private net void
private void button1_Click(object sender, EventArgs e)
{
DialogResult dialogResult = folderBrowserDialog1.ShowDialog();
if (dialogResult == DialogResult.OK)
{
DirectoryInfo directoryInfos = new DirectoryInfo(folderBrowserDialog1.SelectedPath);
TreeNode treeNode = new TreeNode();
treeNode.Text = directoryInfos.Name;
treeView1.Nodes.Add(treeNode);
Tree(treeNode, directoryInfos);
}
}
public void Tree(TreeNode treeNode, DirectoryInfo directoryInfo)
{
DirectoryInfo[] directoryInfos = directoryInfo.GetDirectories();
foreach (DirectoryInfo item in directoryInfos)
{
TreeNode tree = new TreeNode();
tree.Text = item.Name;
treeNode.Nodes.Add(tree);
FileInfo[] fileInfos = item.GetFiles();
if (fileInfos != null)
{
foreach (var items in fileInfos)
{
TreeNode tr = new TreeNode();
tr.Text = items.Name;
tree.Nodes.Add(tr);
}
}
Tree(tree, item);
}
}
标签:ext cto eve node public TreeView private net void
原文地址:https://www.cnblogs.com/LYYXXXX/p/10386134.html