Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Spanning Multiple TreeViews And Handling Duplicate Paths

Thread Tools

Spanning Multiple TreeViews And Handling Duplicate Paths

Posts: n/a

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
data strings: /root/child1/child2/child3 ---> [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.




should really be:


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


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

TreeGen(GetValue(content[i].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 +


TreeNode parent = root;

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

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

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

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.
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding TreeViews Chris Fulstow ASP .Net 2 04-18-2006 02:52 PM
Globa Variables And TreeViews =?Utf-8?B?QW5vbnltb3Vz?= ASP .Net 5 12-15-2004 10:19 PM
MVC and TreeViews j_mckitrick Python 0 06-04-2004 05:52 PM
Adding multiple Treeviews at run-time Jon. Slocombe. ASP .Net Web Controls 0 05-17-2004 09:46 AM
Spanning Tree And Per Vlan Spanning Tree Amy L. Cisco 0 07-24-2003 10:01 PM