How to access a parent with the level as index?

Hi,

I''m working in different levels and i always need to get the correct text of a parent.

Example:
Currently i''m on level 3 and i have to access it this way.
e.Node.Parent.Parent.Text

But if i''m on level 5 it has to be like this
e.Node.Parent.Parent.Parent.Parent.Text

So it''s much better accessing the correct
Parentnode with level as index.

How can i realize this?

thx
Dennis

2 Replies

AD Administrator Syncfusion Team July 20, 2006 05:25 PM UTC

I am not sure what kind of thing e.Node is? I do not that we have any such e.Node properties in any of our grids (but may be wrong).

You can probably write a recursive method like this. I am not sure exactly what test you use, but for the sake of this pseudo code, I will assume Node has a property Level that is zero when you are at the outer most node.


private Node GetOuterNode(Node n)
{
if(n.Level == 0)
return n;
GetOuterNode(n.Parent); //recursive call

}


AD Administrator Syncfusion Team July 20, 2006 09:48 PM UTC

This is strictly psuedo code in that I do not know what the classes are. But I did see a mistake in the previous snippet I posted.

private Node GetOuterNode(Node n)
{
if(n.Level == 0)
return n;
return GetOuterNode(n.Parent); //recursive call

}

Loader.
Up arrow icon