Final Stretch for TreeView Woes - Need Heroic Suggestions

P

pbd22

Hi.

I am almost done my treeview find-or-create logic
but keep getting parent nodes as parents of other
parent nodes... er, if you follow me. For example:

/parent
......../child
.........../file1
.........../file2
.........../file3
.........../file4
......./parent
.........../child
............../file1
.............../file2
.............../file3
.............../file4

Can anybody stop where I am doing this?

Thanks!

protected void TreeGen(string data)
{

string[] arr = data.Split('/');

int count = 0;

if (arr[0] == "")
count = 1;

int files = arr.Length - count;

TreeNode parent = null;

TreeNode root = TreeTrimmer(vTreeView.Nodes, arr[count]);
root.ImageUrl = "folder.gif";

parent = root;

for (int n = count; n < arr.Length; n++)
{

parent = TreeTrimmer(parent.ChildNodes, arr[n]);

}

}


/*
*
* FIND - OR - CREATE
*
*/

private TreeNode TreeTrimmer(TreeNodeCollection nodes, string
name)
{

TreeNode child = null;

foreach (TreeNode tn in nodes)
{
if (tn.Text == name)
{
child = tn;
break;
}

}

if (child == null)
{

child = new TreeNode();
child.Text = name;
nodes.Add(child);

}

return child;

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top