Spanning Multiple TreeViews And Handling Duplicate Paths

Discussion in 'ASP .Net' started by pbd22, Nov 18, 2007.

  1. pbd22

    pbd22 Guest

    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.
    pbd22, Nov 18, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QW5vbnltb3Vz?=

    Globa Variables And TreeViews

    =?Utf-8?B?QW5vbnltb3Vz?=, Dec 15, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    348
    Lowell Heddings
    Dec 15, 2004
  2. j_mckitrick

    MVC and TreeViews

    j_mckitrick, Jun 4, 2004, in forum: Python
    Replies:
    0
    Views:
    352
    j_mckitrick
    Jun 4, 2004
  3. Sriram Rajagopalan

    Syntax for variable names spanning multiple lines in C

    Sriram Rajagopalan, Nov 13, 2006, in forum: C Programming
    Replies:
    28
    Views:
    831
    Richard Bos
    Nov 16, 2006
  4. Mark
    Replies:
    4
    Views:
    1,212
    Hermann Peifer
    Mar 27, 2009
  5. Jon. Slocombe.

    Adding multiple Treeviews at run-time

    Jon. Slocombe., May 17, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    107
    Jon. Slocombe.
    May 17, 2004
Loading...

Share This Page