B4J Question List into hierarchy List

MarkusR

Well-Known Member
Licensed User
hello,
i need an idea.

i have a item with property "A" and "B"
A is parent from B or B is child from A

from this items i have a list (it describes a status workflow from to)
and i need to bring them to a hierarchy view but i don't know which is the root.



X,Z
A,B
D,G
Z,A
B,D

Output should be o_O
X
--Z
-----A
---------B
--------------D
-------------------G

i think i need to iterate through the first property and find the matching "to" and "from" other item. somehow recursive.
 

Philip Chatzigeorgiadis

Active Member
Licensed User
Here is a quick idea:
Search the list once and find the root (the one that never appears in child column) and its child (let's call them Q and R, respectively).
These 2 have levels 1 and 2, respectively.
Then search the list again to find the child of R, (let it be S) which will have level 3.
Then search the list again to find the child of S, (let it be T) which will have level 4.
Etc.
Repeat until all items have a level assigned.

I think the above could also work for multiple items being in the same level or multiple children from a same parent.

Once you have assigned levels to all items, it will be easy to output them in hierarchical form.
 

MarkusR

Well-Known Member
Licensed User
i will try
 
Top