0
我有一個加載選定目錄樹的Treeview
。現在我想使目錄有一個文件夾圖像和文件一個文件圖像。文件夾和文件圖像都在連接到我的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;
}
@KingKong謝謝!完美的作品! – daJbot