Removing Nodes from treeview
Hi guys,
I have come to a little problem with my program. I am displaying files from 'Application.StartupPath' but I trying to get rid of the ParentNode which is the "Debug" folder.
I've got this so far, but no joy:
//Search
private void button10_Click(object sender, EventArgs e)
{
ListDirectorySearch(treeView1, Application.StartupPath);
//Search dir and populate
public TreeNode CreateDirectoryNodeSearch(DirectoryInfo directoryInfo)
{
var directoryNode = new TreeNode(directoryInfo.Name);
foreach (var directory in directoryInfo.GetDirectories())
if (directoryInfo.Name == "Debug")
{
treeView1.Nodes.Remove(directoryNode);
}
else
{
directoryNode.Nodes.Add(CreateDirectoryNodeSearch(directory));
}
foreach (var file in directoryInfo.GetFiles("*" + textBox1.Text + "*.PDF").
Union(directoryInfo.GetFiles("*.WMV").Union(directoryInfo.GetFiles("*.Mov"))))
directoryNode.Nodes.Add(new TreeNode(file.Name));
if (directoryNode.Nodes.Count == 0)
{
directoryNode.Nodes.Add("Sorry, No Books Here");
}
return directoryNode;
}
private void ListDirectorySearch(TreeView treeView, string path)
{
treeView.Nodes.Clear();
var rootDirectoryInfo = new DirectoryInfo(path);
treeView.Nodes.Add(CreateDirectoryNodeSearch(rootDirectoryInfo));
}
so to clarify, my result are:
Debug <---- (this is what I want to get rid of)
- folder1
- file1
- file2
- folder2
- newfile1
Thanks All