472,374 Members | 1,309 Online

# 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 3177
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

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;
}

-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
} }

-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

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
}
}

-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;
}
}

-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

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
}
}

-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;
}
}

-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
>
> 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
}
> }
>
>
> -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 thread has been closed and replies have been disabled. Please start a new discussion.