我是在树视图中从FTP导入数据。
因为它显示的树视图没有任何名称(节点)..只有结构可见
我的代码是,
treeView1.Nodes.Clear();
treeView1.Nodes.Add(CreateDirectoryNode(root, "root"));
private TreeNode CreateDirectoryNode(string root, string p)
{
var directoryNode = new TreeNode(name);
var directoryListing = GetDirectoryListing(path);
var directories = directoryListing.Where(d => d.IsDirectory);
var files = directoryListing.Where(d => !d.IsDirectory);
foreach (var dir in directories)
{
directoryNode.Nodes.Add(CreateDirectoryNode(dir.FullPath, dir.Name));
}
foreach (var file in files)
{
directoryNode.Nodes.Add(new TreeNode(file.Name));
}
return directoryNode;
}
答案 0 :(得分:0)
var directoryNode = new TreeNode(name);
当然应该是......
var directoryNode = new TreeNode(p);
..基于您的方法签名?
您的方法中也不存在name
和path
。
答案 1 :(得分:0)
尝试
directoryNode.Text = name;
来自MSDN TreeNode Class 的
文本 - 获取或设置树节点标签中显示的文本。
尝试:
private TreeNode CreateDirectoryNode(string root, string p)
{
var directoryNode = new TreeNode(name);
directoryNode.Text = name;
var directoryListing = GetDirectoryListing(path);
var directories = directoryListing.Where(d => d.IsDirectory);
var files = directoryListing.Where(d => !d.IsDirectory);
foreach (var dir in directories)
{
directoryNode.Nodes.Add(CreateDirectoryNode(dir.FullPath, dir.Name));
}
foreach (var file in files)
{
TreeNode tn = new TreeNode(file.Name);
tn.Text = file.Name
directoryNode.Nodes.Add(new TreeNode(tn));
}
return directoryNode;
}
我不确定变量“name”和“path”来自何处?我猜他们等于root和p?我会留给你清理