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;
}
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;
}