I ran into a discrepancy with indexes of nodes in a tree view. This tree has only 2 levels of hierarchy, a number of root nodes and a number of nodes under each of those. When I read TTreeView.Selected.Index
, I get the index of the root node only, but when I read TTreeView.Items[TTreeView.Selected.Index]
(iterating in a loop), I get a completely different tree node.
A more specific example, suppose I have this data:
Now suppose I select "Root 3" and read TTreeView.Selected.Index
, it will return 2
. However, when I read TTreeView.Items[2]
it returns "Item 1.2" because it's really the third item in the list. The one I have selected "Root 3" is index number 8 in reality.
What would be the correct way to read the index of the currently selected root node so I get 8
instead of 2
?
TTreeNode.Index
is relative to TTreeNode.Parent
. TTreeView.Items[]
uses absolute indexes, so use TTreeNode.AbsoluteIndex
instead. However, Items[Selected.AbsoluteIndex]
is redundant and inefficient, as it returns the same TTreeNode
that Selected
returns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With