我使用treeView在表单上的treeView中显示序列目录及其子目录和文件,并使用以下方法加载树视图
在表单加载中:
treeView1.Nodes.Clear();
toolTip1.ShowAlways = true;
LoadDirectory("C:\\Windows\\System32\\" + inventedName );
以及以下3种加载目录、子目录和文件的方法
public void LoadDirectory(string Dir)
{
DirectoryInfo di = new DirectoryInfo(Dir);
TreeNode tds = treeView1.Nodes.Add(di.Name);
tds.Tag = di.FullName;
//tds.StateImageIndex = 0;
tds.ImageIndex = 0;
tds.StateImageIndex = 0;
tds.SelectedImageIndex = 0;
LoadFiles(Dir, tds);
LoadSubDirectories(Dir, tds);
}
private void LoadSubDirectories(string dir, TreeNode td)
{
string[] subdirectoryEntries = Directory.GetDirectories(dir);
// Loop through them to see if they have any other subdirectories
foreach (string subdirectory in subdirectoryEntries)
{
DirectoryInfo di = new DirectoryInfo(subdirectory);
TreeNode tds = td.Nodes.Add(di.Name);
renameNodes(tds);
//tds.StateImageIndex = 0;
tds.Tag = di.FullName;
tds.ImageIndex = 0;
tds.StateImageIndex = 0;
tds.SelectedImageIndex = 0;
LoadFiles(subdirectory, tds);
LoadSubDirectories(subdirectory, tds);
}
}
private void LoadFiles(string dir, TreeNode td)
{
string[] Files = Directory.GetFiles(dir, "*.pdf");
// Loop through them to see files
foreach (string file in Files)
{
FileInfo fi = new FileInfo(file);
TreeNode tds = td.Nodes.Add(fi.Name);
tds.Tag = fi.FullName;
tds.ImageIndex = 1;
tds.StateImageIndex = 1;
tds.SelectedImageIndex = 1;
}
}
我的问题是子目录(文件夹)有特定的名称,我不能更改它,例如:
> root
> parent
> 1.0 xxx
> 1.10 xxx
> 1.2 xxx
> 1.3 xxx
> 1.4 xxx
> 1.5 xxx
> 1.6 xxx
> 1.7 xxx
> 1.8 xxx
> 1.9 xxx
但我需要它是这样的
> root
> parent
> 1.0 xxx
> 1.2 xxx
> 1.3 xxx
> 1.4 xxx
> 1.5 xxx
> 1.6 xxx
> 1.7 xxx
> 1.8 xxx
> 1.9 xxx
> 1.10 xxx
愚蠢的(1.10xxx)子文件夹必须在(1.9xxx)子文件夹之后,并且正如我所说的,我不能重命名文件夹,这将是错误的,有什么方法可以将其发送到最后一个子文件夹
谢谢你帮我
https://stackoverflow.com/questions/55764366
复制相似问题