使用设计器创建带有 ListView 和 TreeView 控件的资源管理器样式的界面

peterzhang2008 2008-12-07 02:39:55
怎样确定Node的访问深度,不全取

实现代码以便将节点和子节点填充到 TreeView 中。示例代码从文件系统读取,并且要求 imageList1 中存在两个之前添加的图标 folder.ico 和 doc.ico。

C# 代码
private void PopulateTreeView()
{
TreeNode rootNode;

DirectoryInfo info = new DirectoryInfo(@"C:\Documents and Settings");
if (info.Exists)
{
rootNode = new TreeNode(info.Name);
rootNode.Tag = info;
GetDirectories(info.GetDirectories(), rootNode);
treeView1.Nodes.Add(rootNode);
}
}

private void GetDirectories(DirectoryInfo[] subDirs,
TreeNode nodeToAddTo)
{
TreeNode aNode;
DirectoryInfo[] subSubDirs;
foreach (DirectoryInfo subDir in subDirs)
{
aNode = new TreeNode(subDir.Name, 0, 0);
aNode.Tag = subDir;
aNode.ImageKey = "folder";
subSubDirs = subDir.GetDirectories();
if (subSubDirs.Length != 0)
{
GetDirectories(subSubDirs, aNode);
}
nodeToAddTo.Nodes.Add(aNode);
}
}
...全文
58 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
peterzhang2008 2009-08-14
  • 打赏
  • 举报
回复
呵呵,怎么没人帮我看看啊

4,171

社区成员

发帖
与我相关
我的任务
社区描述
Windows专区 一般软件使用
社区管理员
  • 一般软件使用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧