Iterate over top two levels of Treeview nodes?
-
@Taytoo said in Iterate over top two levels of Treeview nodes?:
@JonB That's what I'm doing currently. Was hoping there was a better way to get nodes of n-levels as a singular list and iterate over them.
It is possible by using a different representation of the tree. It is not immediately straightforward though. Typically trees can be 'linearized' by keeping a left:right traversal index (the so-called "nested set model").
-
@Taytoo said in Iterate over top two levels of Treeview nodes?:
Was hoping there was a better way to get nodes of n-levels as a singular list and iterate over them.
There is, but that is not what you asked for. You wrote:
is there a simple way to iterate in a single loop over the top two levels
My answer would not scale for n-levels. Nor would it be right for "visit every node which is not a leaf". One would probably do either of those recursively. And it would not be a "single loop", which I now notice but did not before, if that is what is vital to you. So you have to state exactly what it is you are looking for.