Sunday, December 28, 2014

How can i add a file name(the text of the file name) as a child node to existing node in a treeView1 ?


bool exists = false;
TreeNode newNodeParsed = null;
TreeNode rootNode = treeViewMS1.Nodes[0];
TreeNode nextNode = rootNode;
string f = Path.GetFileName(txtUploadFile.Text);
TreeNode subnode = new TreeNode(txtDir.Text);
TreeNode filename = new TreeNode(f);
if (!txtDir.Text.Contains("/"))
{
foreach (TreeNode node in rootNode.Nodes)
{
if (node.Text == txtDir.Text)
{
exists = true;
break;
}

}
if (exists == true)
{
subnode.Nodes.Add(f);
}
else
{
rootNode.Nodes.Add(subnode);
subnode.Nodes.Add(f);
}
}

The rootNode is the root directory in the treeView1



subnode is a node inside the root. For example the subnode name is manuelisback


I'm checking if the subnode exist i want to add the file for example (lightning1.jpg) to be under subnode.


If the subnode is not existing add the subnode to the root and then add the file name lightning1.jpg under the subnode.


But the file name is never added under the subnode:



I added manualy the lightning1.jpg under test.


But the lightning1.jpg also should be added to be under manuelisback. There should be two lightning1.jpg here.


One under manuelisback and one under test. The one under test i added manualy from my ftp server.


But the one i want to be under manuelisback i'm trying to add from my program and it dosen't add it to there.


And when i'm using a breakpoint i see on subnode the text manuelisback and i see on f the text lightning1.jpg


No comments:

Post a Comment