我有一个Treeview
加载选定目录的树。现在我想让目录有一个文件夹图像,文件有一个文件图像。文件夹和文件图像都imagelist
连接到我的treeview
. 我将如何调整以下代码来做到这一点?
private void ListDirectory(TreeView treeview, string path)
{
treeview.Nodes.Clear();
var rootDirectoryInfo = new DirectoryInfo(path);
treeview.Nodes.Add(CreateDirectoryNode(rootDirectoryInfo));
}
private static TreeNode CreateDirectoryNode(DirectoryInfo directoryInfo)
{
var directoryNode = new TreeNode(directoryInfo.Name);
foreach (var directory in directoryInfo.GetDirectories())
{
directoryNode.Nodes.Add(CreateDirectoryNode(directory));
}
foreach (var file in directoryInfo.GetFiles())
{
directoryNode.Nodes.Add(new TreeNode(file.Name));
}
return directoryNode;
}