tags:

views:

432

answers:

2

Is there a way of getting the position (index) of an item in a CTreeCtrl?
I am interested in the index of a node at its particular level.

I was thinking to maintain the item positions within the item "data" field, but the problem is that my tree is sorted and I cannot predict the position an item will receive (well, only if I sort the items in advance which I would like to avoid).

+1  A: 

I don't think you can. I assumed that maybe the control could be treated as an array (maybe it still can but I can't find a reference).

Anyways, there are no member functions (according to the MFC API) that give you access to that information

cbrulak
Can you think of a way of bypassing this issue? I was thinking to maintain the item positions within the item "data" field, but the problem is that my tree is sorted and I cannot predict the position an item will receive.
Dana
A: 

Get the node handle and then iterate over the elem Iterate over all the elements, while you count the elements, till you reach the right item?

PoweRoy
I was hoping to do it a bit more efficiently than that. My tree can be quite large.
Dana
If you're not using it already, put the index into the Tag field as you add items to the tree-structure (remembering to rebuild when you remove elements)
Ray Hayes