469,636 Members | 1,555 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,636 developers. It's quick & easy.

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 TreeNodeCollection and
treeViewSequence.Nodes.GetEnumerator() But i can't find a way to fix this,
it is difficult to get the child, help me....

Thx
JC

Nov 15 '05 #1
5 3031
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.Count > 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.Nodes.Add(newNode);

-vJ

"Jeroen Ceuppens" <je*************@barco.com> wrote in message
news:eg**************@TK2MSFTNGP10.phx.gbl...

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 TreeNodeCollection and
treeViewSequence.Nodes.GetEnumerator() But i can't find a way to fix this,
it is difficult to get the child, help me....

Thx
JC

Nov 15 '05 #2
Sorry - small correction... Check below

"Vijaye Raji" <no************@hotmail.com> wrote in message
news:9a********************@comcast.com...
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.Count > 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.Nodes.Add(newNode);

-vJ

"Jeroen Ceuppens" <je*************@barco.com> wrote in message
news:eg**************@TK2MSFTNGP10.phx.gbl...

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 TreeNodeCollection and
treeViewSequence.Nodes.GetEnumerator() But i can't find a way to fix this, it is difficult to get the child, help me....

Thx
JC


Nov 15 '05 #3
Thx!

There is still a problem:

C:\Documents and Settings\Eindwerk\Mijn documenten\BARCO\Eindwerk\Project
Files\thuis\29november\TestTree\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" <no************@hotmail.com> schreef in bericht
news:-Y********************@comcast.com...
Sorry - small correction... Check below

"Vijaye Raji" <no************@hotmail.com> wrote in message
news:9a********************@comcast.com...
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.Count > 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.Nodes.Add(newNode);

-vJ

"Jeroen Ceuppens" <je*************@barco.com> wrote in message
news:eg**************@TK2MSFTNGP10.phx.gbl...

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 TreeNodeCollection and
treeViewSequence.Nodes.GetEnumerator() But i can't find a way to fix this, it is difficult to get the child, help me....

Thx
JC



Nov 15 '05 #4
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.Nodes.Add(newNode);

-vJ

"Jeroen Ceuppens" <je*************@barco.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Thx!

There is still a problem:

C:\Documents and Settings\Eindwerk\Mijn documenten\BARCO\Eindwerk\Project
Files\thuis\29november\TestTree\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" <no************@hotmail.com> schreef in bericht
news:-Y********************@comcast.com...
Sorry - small correction... Check below

"Vijaye Raji" <no************@hotmail.com> wrote in message
news:9a********************@comcast.com...
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.Count > 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.Nodes.Add(newNode);

-vJ

"Jeroen Ceuppens" <je*************@barco.com> wrote in message
news:eg**************@TK2MSFTNGP10.phx.gbl...
>
> 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 TreeNodeCollection and
> treeViewSequence.Nodes.GetEnumerator() But i can't find a way to fix

this,
> it is difficult to get the child, help me....
>
> Thx
> JC
>
>
>



Nov 15 '05 #5
YEAH! it works!

Thx a lot dude!

Greetz
JC
"Vijaye Raji" <no************@hotmail.com> schreef in bericht
news:e5**************@TK2MSFTNGP10.phx.gbl...
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.Nodes.Add(newNode);

-vJ

"Jeroen Ceuppens" <je*************@barco.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Thx!

There is still a problem:

C:\Documents and Settings\Eindwerk\Mijn documenten\BARCO\Eindwerk\Project Files\thuis\29november\TestTree\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" <no************@hotmail.com> schreef in bericht
news:-Y********************@comcast.com...
Sorry - small correction... Check below

"Vijaye Raji" <no************@hotmail.com> wrote in message
news:9a********************@comcast.com...
> 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.Count > 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.Nodes.Add(newNode);
>
> -vJ
>
> "Jeroen Ceuppens" <je*************@barco.com> wrote in message
> news:eg**************@TK2MSFTNGP10.phx.gbl...
> >
> > 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 TreeNodeCollection and
> > treeViewSequence.Nodes.GetEnumerator() But i can't find a way to fix this,
> > it is difficult to get the child, help me....
> >
> > Thx
> > JC
> >
> >
> >
>
>



Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by mike | last post: by
3 posts views Thread by pentium77 | last post: by
3 posts views Thread by Robert Oschler | last post: by
4 posts views Thread by Gregory Piñero | last post: by
reply views Thread by Goran Djuranovic | last post: by
7 posts views Thread by mattrapoport | last post: by
1 post views Thread by Bllich | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.