Can't find deepest node

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeroen Ceuppens

    #1

    Can't find deepest node


    I need to put a new node at the end of the tree, that end is not te lowest
    in de list but the deepest
    (the one with the most + before it)

    Node A
    Node 1
    Node 2
    Node 3
    Node 4: Deepest
    Node B: not this one

    I need to Put everytime a new child to the Deepest so:

    first:
    Node A

    then

    Node A
    Node 1

    then

    Node A
    Node 1
    Node 2

    and so on

    I tried many things, like TreeNodeCollect ion and
    treeViewSequenc e.Nodes.GetEnum erator() But i can't find a way to fix this,
    it is difficult to get the child, help me....

    Thx
    JC



  • Vijaye Raji

    #2
    Re: Can't find deepest node

    As I told before, there's no pre-defined method/property for your problem.
    You need to come up with an algorithm.... Do you think something like this
    will solve your problem?

    TreeNode deepest;
    int deepestLevel = 0;
    foreach (TreeNode node in treeView.Nodes)
    {
    // This will get all the top level nodes - and now, let's iterate
    // through each one.
    int level = 0;
    while (node.Nodes.Cou nt > 0)
    {
    level++;
    node = node.Nodes[0];
    }

    // Check if we hit the deepest
    if (level >= deepestLevel)
    deepestNode = node;
    }

    // Now, add your new node to the deepest node
    deepestNode.Nod es.Add(newNode) ;

    -vJ

    "Jeroen Ceuppens" <jeroen.ceuppen s@barco.com> wrote in message
    news:egBobHPuDH A.2060@TK2MSFTN GP10.phx.gbl...[color=blue]
    >
    > I need to put a new node at the end of the tree, that end is not te lowest
    > in de list but the deepest
    > (the one with the most + before it)
    >
    > Node A
    > Node 1
    > Node 2
    > Node 3
    > Node 4: Deepest
    > Node B: not this one
    >
    > I need to Put everytime a new child to the Deepest so:
    >
    > first:
    > Node A
    >
    > then
    >
    > Node A
    > Node 1
    >
    > then
    >
    > Node A
    > Node 1
    > Node 2
    >
    > and so on
    >
    > I tried many things, like TreeNodeCollect ion and
    > treeViewSequenc e.Nodes.GetEnum erator() But i can't find a way to fix this,
    > it is difficult to get the child, help me....
    >
    > Thx
    > JC
    >
    >
    >[/color]


    Comment

    • Vijaye Raji

      #3
      Re: Can't find deepest node

      Sorry - small correction... Check below

      "Vijaye Raji" <nospam_vganesh @hotmail.com> wrote in message
      news:9aSdnZS1S5 AmWFGiRVn-iw@comcast.com. ..[color=blue]
      > As I told before, there's no pre-defined method/property for your problem.
      > You need to come up with an algorithm.... Do you think something like[/color]
      this[color=blue]
      > will solve your problem?
      >
      > TreeNode deepest;
      > int deepestLevel = 0;
      > foreach (TreeNode node in treeView.Nodes)
      > {
      > // This will get all the top level nodes - and now, let's iterate
      > // through each one.
      > int level = 0;
      > while (node.Nodes.Cou nt > 0)
      > {
      > level++;
      > node = node.Nodes[0];
      > }
      >
      > // Check if we hit the deepest
      > if (level >= deepestLevel)[/color]
      {[color=blue]
      > deepestNode = node;[/color]

      // CORRECTION: This line is important.
      deepestLevel = level
      }[color=blue]
      > }
      >
      > // Now, add your new node to the deepest node
      > deepestNode.Nod es.Add(newNode) ;
      >
      > -vJ
      >
      > "Jeroen Ceuppens" <jeroen.ceuppen s@barco.com> wrote in message
      > news:egBobHPuDH A.2060@TK2MSFTN GP10.phx.gbl...[color=green]
      > >
      > > I need to put a new node at the end of the tree, that end is not te[/color][/color]
      lowest[color=blue][color=green]
      > > in de list but the deepest
      > > (the one with the most + before it)
      > >
      > > Node A
      > > Node 1
      > > Node 2
      > > Node 3
      > > Node 4: Deepest
      > > Node B: not this one
      > >
      > > I need to Put everytime a new child to the Deepest so:
      > >
      > > first:
      > > Node A
      > >
      > > then
      > >
      > > Node A
      > > Node 1
      > >
      > > then
      > >
      > > Node A
      > > Node 1
      > > Node 2
      > >
      > > and so on
      > >
      > > I tried many things, like TreeNodeCollect ion and
      > > treeViewSequenc e.Nodes.GetEnum erator() But i can't find a way to fix[/color][/color]
      this,[color=blue][color=green]
      > > it is difficult to get the child, help me....
      > >
      > > Thx
      > > JC
      > >
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Jeroen Ceuppens

        #4
        Re: Can't find deepest node

        Thx!

        There is still a problem:

        C:\Documents and Settings\Eindwe rk\Mijn documenten\BARC O\Eindwerk\Proj ect
        Files\thuis\29n ovember\TestTre e\Form1.cs(206) : Property or indexer
        'System.Windows .Forms.TreeNode .Parent' cannot be assigned to -- it is read
        only

        this error i get on node = node.Nodes[0];
        Do you know what i can do to make it not read only?

        Thx
        JC


        "Vijaye Raji" <nospam_vganesh @hotmail.com> schreef in bericht
        news:-YOdnWjxCsuUVVGi RVn-gg@comcast.com. ..[color=blue]
        > Sorry - small correction... Check below
        >
        > "Vijaye Raji" <nospam_vganesh @hotmail.com> wrote in message
        > news:9aSdnZS1S5 AmWFGiRVn-iw@comcast.com. ..[color=green]
        > > As I told before, there's no pre-defined method/property for your[/color][/color]
        problem.[color=blue][color=green]
        > > You need to come up with an algorithm.... Do you think something like[/color]
        > this[color=green]
        > > will solve your problem?
        > >
        > > TreeNode deepest;
        > > int deepestLevel = 0;
        > > foreach (TreeNode node in treeView.Nodes)
        > > {
        > > // This will get all the top level nodes - and now, let's iterate
        > > // through each one.
        > > int level = 0;
        > > while (node.Nodes.Cou nt > 0)
        > > {
        > > level++;
        > > node = node.Nodes[0];
        > > }
        > >
        > > // Check if we hit the deepest
        > > if (level >= deepestLevel)[/color]
        > {[color=green]
        > > deepestNode = node;[/color]
        >
        > // CORRECTION: This line is important.
        > deepestLevel = level
        > }[color=green]
        > > }
        > >
        > > // Now, add your new node to the deepest node
        > > deepestNode.Nod es.Add(newNode) ;
        > >
        > > -vJ
        > >
        > > "Jeroen Ceuppens" <jeroen.ceuppen s@barco.com> wrote in message
        > > news:egBobHPuDH A.2060@TK2MSFTN GP10.phx.gbl...[color=darkred]
        > > >
        > > > I need to put a new node at the end of the tree, that end is not te[/color][/color]
        > lowest[color=green][color=darkred]
        > > > in de list but the deepest
        > > > (the one with the most + before it)
        > > >
        > > > Node A
        > > > Node 1
        > > > Node 2
        > > > Node 3
        > > > Node 4: Deepest
        > > > Node B: not this one
        > > >
        > > > I need to Put everytime a new child to the Deepest so:
        > > >
        > > > first:
        > > > Node A
        > > >
        > > > then
        > > >
        > > > Node A
        > > > Node 1
        > > >
        > > > then
        > > >
        > > > Node A
        > > > Node 1
        > > > Node 2
        > > >
        > > > and so on
        > > >
        > > > I tried many things, like TreeNodeCollect ion and
        > > > treeViewSequenc e.Nodes.GetEnum erator() But i can't find a way to fix[/color][/color]
        > this,[color=green][color=darkred]
        > > > it is difficult to get the child, help me....
        > > >
        > > > Thx
        > > > JC
        > > >
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Vijaye Raji

          #5
          Re: Can't find deepest node

          Ok.. My mistake... objects from foreach are read-only.

          Here's a modified version:

          TreeNode deepestNode = null;
          int deepestLevel = 0;
          foreach (TreeNode node in treeView1.Nodes )
          {
          // This will get all the top level nodes - and now, let's
          iterate
          // through each one.
          int level = 0;
          TreeNode nodeTemp = node;
          while (nodeTemp.Nodes .Count > 0)
          {
          level++;
          nodeTemp = nodeTemp.Nodes[0];
          }

          // Check if we hit the deepest
          if (level >= deepestLevel)
          {
          deepestNode = nodeTemp;
          deepestLevel = level;
          }
          }
          // Now add your new node
          deepestNode.Nod es.Add(newNode) ;

          -vJ

          "Jeroen Ceuppens" <jeroen.ceuppen s@barco.com> wrote in message
          news:%23JF$8CQu DHA.2360@TK2MSF TNGP09.phx.gbl. ..[color=blue]
          > Thx!
          >
          > There is still a problem:
          >
          > C:\Documents and Settings\Eindwe rk\Mijn documenten\BARC O\Eindwerk\Proj ect
          > Files\thuis\29n ovember\TestTre e\Form1.cs(206) : Property or indexer
          > 'System.Windows .Forms.TreeNode .Parent' cannot be assigned to -- it is read
          > only
          >
          > this error i get on node = node.Nodes[0];
          > Do you know what i can do to make it not read only?
          >
          > Thx
          > JC
          >
          >
          > "Vijaye Raji" <nospam_vganesh @hotmail.com> schreef in bericht
          > news:-YOdnWjxCsuUVVGi RVn-gg@comcast.com. ..[color=green]
          > > Sorry - small correction... Check below
          > >
          > > "Vijaye Raji" <nospam_vganesh @hotmail.com> wrote in message
          > > news:9aSdnZS1S5 AmWFGiRVn-iw@comcast.com. ..[color=darkred]
          > > > As I told before, there's no pre-defined method/property for your[/color][/color]
          > problem.[color=green][color=darkred]
          > > > You need to come up with an algorithm.... Do you think something like[/color]
          > > this[color=darkred]
          > > > will solve your problem?
          > > >
          > > > TreeNode deepest;
          > > > int deepestLevel = 0;
          > > > foreach (TreeNode node in treeView.Nodes)
          > > > {
          > > > // This will get all the top level nodes - and now, let's iterate
          > > > // through each one.
          > > > int level = 0;
          > > > while (node.Nodes.Cou nt > 0)
          > > > {
          > > > level++;
          > > > node = node.Nodes[0];
          > > > }
          > > >
          > > > // Check if we hit the deepest
          > > > if (level >= deepestLevel)[/color]
          > > {[color=darkred]
          > > > deepestNode = node;[/color]
          > >
          > > // CORRECTION: This line is important.
          > > deepestLevel = level
          > > }[color=darkred]
          > > > }
          > > >
          > > > // Now, add your new node to the deepest node
          > > > deepestNode.Nod es.Add(newNode) ;
          > > >
          > > > -vJ
          > > >
          > > > "Jeroen Ceuppens" <jeroen.ceuppen s@barco.com> wrote in message
          > > > news:egBobHPuDH A.2060@TK2MSFTN GP10.phx.gbl...
          > > > >
          > > > > I need to put a new node at the end of the tree, that end is not te[/color]
          > > lowest[color=darkred]
          > > > > in de list but the deepest
          > > > > (the one with the most + before it)
          > > > >
          > > > > Node A
          > > > > Node 1
          > > > > Node 2
          > > > > Node 3
          > > > > Node 4: Deepest
          > > > > Node B: not this one
          > > > >
          > > > > I need to Put everytime a new child to the Deepest so:
          > > > >
          > > > > first:
          > > > > Node A
          > > > >
          > > > > then
          > > > >
          > > > > Node A
          > > > > Node 1
          > > > >
          > > > > then
          > > > >
          > > > > Node A
          > > > > Node 1
          > > > > Node 2
          > > > >
          > > > > and so on
          > > > >
          > > > > I tried many things, like TreeNodeCollect ion and
          > > > > treeViewSequenc e.Nodes.GetEnum erator() But i can't find a way to fix[/color]
          > > this,[color=darkred]
          > > > > it is difficult to get the child, help me....
          > > > >
          > > > > Thx
          > > > > JC
          > > > >
          > > > >
          > > > >
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Jeroen Ceuppens

            #6
            Re: Can't find deepest node

            YEAH! it works!

            Thx a lot dude!

            Greetz
            JC
            "Vijaye Raji" <nospam_vganesh @hotmail.com> schreef in bericht
            news:e5qOVOQuDH A.2072@TK2MSFTN GP10.phx.gbl...[color=blue]
            > Ok.. My mistake... objects from foreach are read-only.
            >
            > Here's a modified version:
            >
            > TreeNode deepestNode = null;
            > int deepestLevel = 0;
            > foreach (TreeNode node in treeView1.Nodes )
            > {
            > // This will get all the top level nodes - and now, let's
            > iterate
            > // through each one.
            > int level = 0;
            > TreeNode nodeTemp = node;
            > while (nodeTemp.Nodes .Count > 0)
            > {
            > level++;
            > nodeTemp = nodeTemp.Nodes[0];
            > }
            >
            > // Check if we hit the deepest
            > if (level >= deepestLevel)
            > {
            > deepestNode = nodeTemp;
            > deepestLevel = level;
            > }
            > }
            > // Now add your new node
            > deepestNode.Nod es.Add(newNode) ;
            >
            > -vJ
            >
            > "Jeroen Ceuppens" <jeroen.ceuppen s@barco.com> wrote in message
            > news:%23JF$8CQu DHA.2360@TK2MSF TNGP09.phx.gbl. ..[color=green]
            > > Thx!
            > >
            > > There is still a problem:
            > >
            > > C:\Documents and Settings\Eindwe rk\Mijn[/color][/color]
            documenten\BARC O\Eindwerk\Proj ect[color=blue][color=green]
            > > Files\thuis\29n ovember\TestTre e\Form1.cs(206) : Property or indexer
            > > 'System.Windows .Forms.TreeNode .Parent' cannot be assigned to -- it is[/color][/color]
            read[color=blue][color=green]
            > > only
            > >
            > > this error i get on node = node.Nodes[0];
            > > Do you know what i can do to make it not read only?
            > >
            > > Thx
            > > JC
            > >
            > >
            > > "Vijaye Raji" <nospam_vganesh @hotmail.com> schreef in bericht
            > > news:-YOdnWjxCsuUVVGi RVn-gg@comcast.com. ..[color=darkred]
            > > > Sorry - small correction... Check below
            > > >
            > > > "Vijaye Raji" <nospam_vganesh @hotmail.com> wrote in message
            > > > news:9aSdnZS1S5 AmWFGiRVn-iw@comcast.com. ..
            > > > > As I told before, there's no pre-defined method/property for your[/color]
            > > problem.[color=darkred]
            > > > > You need to come up with an algorithm.... Do you think something[/color][/color][/color]
            like[color=blue][color=green][color=darkred]
            > > > this
            > > > > will solve your problem?
            > > > >
            > > > > TreeNode deepest;
            > > > > int deepestLevel = 0;
            > > > > foreach (TreeNode node in treeView.Nodes)
            > > > > {
            > > > > // This will get all the top level nodes - and now, let's[/color][/color][/color]
            iterate[color=blue][color=green][color=darkred]
            > > > > // through each one.
            > > > > int level = 0;
            > > > > while (node.Nodes.Cou nt > 0)
            > > > > {
            > > > > level++;
            > > > > node = node.Nodes[0];
            > > > > }
            > > > >
            > > > > // Check if we hit the deepest
            > > > > if (level >= deepestLevel)
            > > > {
            > > > > deepestNode = node;
            > > >
            > > > // CORRECTION: This line is important.
            > > > deepestLevel = level
            > > > }
            > > > > }
            > > > >
            > > > > // Now, add your new node to the deepest node
            > > > > deepestNode.Nod es.Add(newNode) ;
            > > > >
            > > > > -vJ
            > > > >
            > > > > "Jeroen Ceuppens" <jeroen.ceuppen s@barco.com> wrote in message
            > > > > news:egBobHPuDH A.2060@TK2MSFTN GP10.phx.gbl...
            > > > > >
            > > > > > I need to put a new node at the end of the tree, that end is not[/color][/color][/color]
            te[color=blue][color=green][color=darkred]
            > > > lowest
            > > > > > in de list but the deepest
            > > > > > (the one with the most + before it)
            > > > > >
            > > > > > Node A
            > > > > > Node 1
            > > > > > Node 2
            > > > > > Node 3
            > > > > > Node 4: Deepest
            > > > > > Node B: not this one
            > > > > >
            > > > > > I need to Put everytime a new child to the Deepest so:
            > > > > >
            > > > > > first:
            > > > > > Node A
            > > > > >
            > > > > > then
            > > > > >
            > > > > > Node A
            > > > > > Node 1
            > > > > >
            > > > > > then
            > > > > >
            > > > > > Node A
            > > > > > Node 1
            > > > > > Node 2
            > > > > >
            > > > > > and so on
            > > > > >
            > > > > > I tried many things, like TreeNodeCollect ion and
            > > > > > treeViewSequenc e.Nodes.GetEnum erator() But i can't find a way to[/color][/color][/color]
            fix[color=blue][color=green][color=darkred]
            > > > this,
            > > > > > it is difficult to get the child, help me....
            > > > > >
            > > > > > Thx
            > > > > > JC
            > > > > >
            > > > > >
            > > > > >
            > > > >
            > > > >
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            Working...