Spanning Multiple TreeViews And Handling Duplicate Paths

P

pbd22

Hi.

I am wondering if somebody could help me understand how to span
multiple treeviews?

I have a treeview that currently builds small trees based on arrays of
simple
data strings: /root/child1/child2/child3 ---> [root],[child1],[child2],
[child3]

/root
/child1
/child2

/root
/child1
/child2

so, the result is several trees on the client.

MY PROBELM: is that I need to eliminate duplicate paths in the trees.
So,

/classical
/mozart
/requiem

and

/classical
/mozart
/waltz

should really be:

/classical
/mozart
/requiem
/waltz



In the below code the primary loop takes a string with a path:

"/classical/mozart/requiem"


for (int i = 0; content != null && i < content.Length; i++)
{

TreeGen(GetValue(content.data, TITLE));

}


and passes it to TreeGen which, in turn, makes it into an array
and then builds it into a tree.

protected void TreeGen(string data)
{

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

int count = 0;

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

int files = arr.Length - count;

TreeNode root = new TreeNode();
root.ImageUrl = "folder.gif";
root.Text += arr[count] + "&nbsp;(" + files +
"&nbsp;files)";
count++;

vTreeView.Nodes.Add(root);

TreeNode parent = root;

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

if (RecurseNodes(vTreeView.Nodes, arr[n].ToString())
== true)
continue;

TreeNode child = new TreeNode();
child.Text = arr[n].ToString();

parent.ChildNodes.Add(child);
parent = child;

}

}


So, after the above function I have a small tree. After several
iterations, I get several
small trees, many with the same node paths except the final file. I
need a way of
checking paths and adding a node if it doesn't exist. I am trying to
do that with the
RecurseNodes function below (span the tree, if the node doesn't exist,
add it to the
preexisting path or create a new one). I can't seem to get this to
work though, and
would appreciate some help:


private static bool RecurseNodes(TreeNodeCollection Node,
string name)
{

foreach (TreeNode tn in Node)
{
if (tn.Text == name)
return true;

RecurseNodes(tn.ChildNodes, name);
}

return false;
}

Thank you.
 

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,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top