I am using a tree view in c# and i am creating custom icons for the nodes.
Let say this is my hierarchy with a node that satisfies a certain condition:
Root1
|_Ax
|_Bx1
|_Bx2
|_Cx1
|_Cx2(condition true)
|_Bx3
|_Bx4
|_Ay
|_By1
|_By2
|_Cy1
when the tree it’s collapsed I don’t know if some inner child satisfies that particular condition so I want to display an icon on the topmost un-expanded parent.
For example let say that the tree it’s completely collapsed I would like this behaviour :
1) the first root will be like this :
Root1(!)
2) I expand Root1 and i see there is something the children of Ax :
Root1
|_Ax(!)
|_Ay
3) I expand Ax :
Root1
|_Ax
|_Bx1
|_Bx2(!)
|_Bx3
|_Bx4
|_Ay
4) Last I expand Bx2 to find the target node Cx2:
Root1
|_Ax
|_Bx1
|_Bx2
|_Cx1
|_Cx2(condition true)
|_Bx3
|_Bx4
|_Ay
The symbol (!) appears only on the topmost un-expanded parent and disappears once the node is expanded indicating a path to locate the target node Cx2.
But I would like some idea on how to add the node indicator (!) in an efficient fashion.
I need to do this in 2 steps
– tree creation
– node expanded
In the first case as soon as I create the node Cx2 and I notice it satisfies that particular condition I need to put the indicator on the topmost unexpanded parent node.
In the second case I need to change the indicator location dynamically when the node it`s expanded.
What is the most efficient way to do that ?
1
I don’t think recursion is the efficient way to solve this because on expanding the marked node you would have to apply that recursion on every single one of its children.
A marked node should carry information (e.g. in form of a list, array, …) which of its descendants are matching the condition. So if that marked node gets expanded you would just start at the condition-matching node and go up until you reach the first visible node an mark it. After you have done this for every descendant you remove the marker from the now expanded parent node.