Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

Spanning Multiple TreeViews And Handling Duplicate Paths

 
 
pbd22
Guest
Posts: n/a
 
      11-18-2007
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[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 +
"&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.
 
Reply With Quote
 
 
 
Reply

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



Advertisments