private void treeView1_MouseClick(object sender, MouseEventArgs e)
{
// Get the node that was clicked
TreeNode selectedNode = treeView1.HitTest(e.Location).Node;
if (selectedNode != null)
{
}
}
If I have for example a root node:
World
When I click on it I see these nodes:
World
|____ Blue
|____ Green
|____ Red
|____ Black
|____ yellow
If I click on Blue I will see more nodes under Blue for example
World
|____ Blue
| |____ Day
| |____ Night
|____ Green
|____ Red
|____ Black
|____ yellow
Now if I click on Blue I will get the selected node name Blue. selectedNode.Name
will be Blue
And if I click on Day will get in selectedNode.Name
Day
But what I want to do is that if I click on Day the selectedNode
be
Blue\Day or BlueDay
And if under Day there is another node name 1 and I click on 1 so in selectedNode.Name I want to see BlueDay1 or I prefer Blue\Day\1
I want this \\
so I can use it as a directory name.
The problem is i'm using the selectedNode.Name
as a directory to get files:
List<string> ff = new List<string>();
private void treeView1_MouseClick(object sender, MouseEventArgs e)
{
TreeNode selectedNode = treeView1.HitTest(e.Location).Node;
if (selectedNode != null)
{
string tt = mainPath + "\\" + selectedNode.Text;
ff = DirSearch(tt);
timer1.Enabled = true;
}
}
If I click on Blue then it's fine it will get all the files under Blue including sub directories. But if i click on 1 and there are files in 1 then it will not get any files since i need the complete path name Blue\Day\1 to get the files from 1.
This is how I'm getting the files
static List<string> DirSearch(string sDir)
{
List<string> files = new List<string>();
try
{
foreach (string d in Directory.GetDirectories(sDir))
{
foreach (string f in Directory.GetFiles(d))
{
files.Add(f);
}
DirSearch(d);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}
return files;
}
The idea is if I want to get all the files under Blue I click on Blue but if I want to get only the files in 1 when I click on 1 it's not working since 1 is not the complete path.