Ex.:
- link 1 -- link 1.1 --- link 1.1.1(only) ---- link 1.1.1.1 (not expand) -- link 1.2 --- link 1.2.1 (only) ---- link 1.2.1.1 (not expand)
I can expand only link 1.1, link 1.2... how?
Ex.:
- link 1 -- link 1.1 --- link 1.1.1(only) ---- link 1.1.1.1 (not expand) -- link 1.2 --- link 1.2.1 (only) ---- link 1.2.1.1 (not expand)
I can expand only link 1.1, link 1.2... how?
There is no build-in functionality for expanding multiple items or items on a specific level, so there is no other way then traversing through the items. Call the
Expand
method on all second level items. As well on all first level items, otherwise the second level items will not be shown. ItsRecurse
parameter should beFalse
in order not to expand a possibly third or deeper level.There are two ways to traverse through a TreeView's items: by Item index and by Node. Normally, operations on a TreeView's items are preferably done by Node, because the
Items
property's getter traverses through all Items to find a single Item with a specific index. However,TTreeNodes
caches the last retrieved item, thus by incrementing the loop Index with 1, harm will be minimized.The easy solution then becomes:
Note that the
Items
property's getter is still called twice. Despite the caching mechanism, I think this still should be avoided:But then you might as well use:
This still traverses áll Items. Ok, just once. But if you have a really big and/or deep tree, and you want maximum efficiency, and you do not care about readability, or you just want to experiment with a TreeView's Nodes for fun, then use: