文件链表关系(散分)
实现和windows操作系统一样的文件目录关系,
用treeview 邦定数据
------解决方案--------------------private void FolderTree_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
if(e.Node.Text.ToString()!= "我的电脑 ")
EnumDirectories(e.Node);
else
EnumDrives(e.Node);
}
private void EnumDrives(TreeNode ParentNode)
{
try
{
if (ParentNode.Nodes.Count == 0)
{
foreach (string drive in Directory.GetLogicalDrives())
{
FolderTree.SelectedNode = ParentNode;
TreeNode TempNode = new TreeNode();
TempNode.Text = drive.Substring(0, drive.Length - 1);
TempNode.Tag = drive;
TempNode.ImageIndex = 1;
TempNode.SelectedImageIndex = 1;
FolderTree.SelectedNode.Nodes.Add(TempNode);
FolderTree.SelectedNode.Nodes[FolderTree.SelectedNode.Nodes.Count - 1].EnsureVisible();
}
}
}
catch (Exception t)
{
MessageBox.Show(t.Message);
}
}
private void EnumDirectories(TreeNode ParentNode)
{
FolderTree.SelectedNode=ParentNode;
string DirectoryPath=ParentNode.Tag.ToString();
if(ParentNode.Nodes.Count==0)
{
if(DirectoryPath.Substring(DirectoryPath.Length-1)!=@ "\ ")
DirectoryPath+=@ "\ ";
try
{
foreach(string directory in Directory.GetDirectories(DirectoryPath))
{
TreeNode TempNode=new TreeNode();
TempNode.Text=directory.Substring(directory.LastIndexOf(@ "\ ")+1);
TempNode.Tag=directory;
TempNode.ImageIndex=3;
TempNode.SelectedImageIndex=2;
FolderTree.SelectedNode.Nodes.Add(TempNode);
FolderTree.SelectedNode.Nodes[FolderTree.SelectedNode.Nodes.Count-1].EnsureVisible();
}
}
catch(Exception t)
{
MessageBox.Show(t.Message);
}
}
}
}
这是树型目录的代码
------解决方案--------------------帮顶一下
------解决方案--------------------学习
------解决方案--------------------路过
------解决方案--------------------楼上做沙发的那人说的就是TreeView绑定数据库的代码~~
楼主看看先~~~
不行的话再说,关注中
------解决方案--------------------帮顶
------解决方案--------------------用递归遍历,动态添加Node
------解决方案--------------------我顶...
------解决方案--------------------UP
------解决方案--------------------