Your fundamental problem is a mis-understanding of the meaning of the indexed property
TTreeView.Items[]
Your believe that this accesses just the top level nodes. That is not so. This property gives access to each and every node in the tree. The way to understand that is to look at your tree, expand all folders, and read downwards from the top ignoring nesting. For your tree, the indexing looks like this:
Index TreeView1.Items[Index]
----- ----------------------
0 Pay History
1 Summary
2 Detail
3 Specific Account History
4 Summary
5 Detail
.... ....
So when you refer to TreeView1.Items[2]
you are actually getting the node with caption Detail that is a child of the very first node, that named Pay History.
The node that you want has index 13 so you can change your code to be
TreeView1.Items[13].Text := ...;
The other property that you are using is TTreeNode.Item[]
. This is different again. This access the list of direct children of a particular node. So, TTreeView1.Items[0].Item[]
can be used to access the two nodes that are children of the first node, that named Pay History.
In your situation I would not want to write:
TreeView1.Items[13].Text := ...;
I would reject code that relied on a magic number like that. I would populate the tree view at runtime and save away in instance variables references to any nodes that I needed to use later. For example:
FPayHistoryNode := TreeView1.Add(nil, 'Pay History');
FPayHistorySummaryNode := TreeView1.AddChild(FPayHistoryNode, 'Summary');
FPayHistoryDetailNode := TreeView1.AddChild(FPayHistoryNode, 'Detail');
....
If you need to modify properties of the node later then you can do so with code that can be understood at a glance by the reader. And when you insert new nodes, or re-order the nodes, you don't break all your existing code as you would with a magic constant.