sun307
asked on
Getting the index of CTreeCtrl item
Hi !
I want to get the index of the selected node in my CTreeCtrl. When i do a getselecteditem() then it returns a HTREEITEM type. where as i wants the index number of that particular node at that level.
How can i do that.
Thanx in advance
Regards,
Sun307
I want to get the index of the selected node in my CTreeCtrl. When i do a getselecteditem() then it returns a HTREEITEM type. where as i wants the index number of that particular node at that level.
How can i do that.
Thanx in advance
Regards,
Sun307
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
One more method, to get index. Store the specific index value while inserting itself using lParam parameter of TV_ITEM, as
TV_INSERTSTRUCT TreeCtrlItem;
TreeCtrlItem.item.lParam = 0;
and set other parameters and insert it,
Then while inserting childs give specific values. To retrive that,
HTREEITEM hTreeItem = m_Property.GetSelectedItem ();
TV_ITEM TreeCtrlItem;
TreeCtrlItem.mask = TVIF_HANDLE | TVIF_PARAM;
TreeCtrlItem.hItem = hTreeItem;
m_Property.GetItem(&TreeCt rlItem);
Now TreeCtrlItem.lParam will give u the value which is specified by U. Here m_Property is the control variable for CTreeCtrl.
For datails U can look into the code of vc++ sample FIRE.
Hope this helps.
VinExpert
One more method, to get index. Store the specific index value while inserting itself using lParam parameter of TV_ITEM, as
TV_INSERTSTRUCT TreeCtrlItem;
TreeCtrlItem.item.lParam = 0;
and set other parameters and insert it,
Then while inserting childs give specific values. To retrive that,
HTREEITEM hTreeItem = m_Property.GetSelectedItem
TV_ITEM TreeCtrlItem;
TreeCtrlItem.mask = TVIF_HANDLE | TVIF_PARAM;
TreeCtrlItem.hItem = hTreeItem;
m_Property.GetItem(&TreeCt
Now TreeCtrlItem.lParam will give u the value which is specified by U. Here m_Property is the control variable for CTreeCtrl.
For datails U can look into the code of vc++ sample FIRE.
Hope this helps.
VinExpert
> One more method, to get index.
That doesn't store (or retrieve) an index. It stores or retrieves an arbitrary value.
..B ekiM
That doesn't store (or retrieve) an index. It stores or retrieves an arbitrary value.
..B ekiM
Hi,
That is correct. But I can give some specific value like index and retrieve it back.
VinExpert
That is correct. But I can give some specific value like index and retrieve it back.
VinExpert
> But I can give some specific value like index and retrieve it back.
Yeah. Since items can be removed and inserted at any time, you'll have to enumerate all the children and adjust their lParams if you want the lParam to represent the index relative to the other children in the node. That doesn't sound like a very good idea to me.
..B ekiM
Yeah. Since items can be removed and inserted at any time, you'll have to enumerate all the children and adjust their lParams if you want the lParam to represent the index relative to the other children in the node. That doesn't sound like a very good idea to me.
..B ekiM
Hi mikeblas,
I agree that it is complex, But it can be done. And it can be done easily if U know the items and childs associated (at least I think so :-))
VinExpert
I agree that it is complex, But it can be done. And it can be done easily if U know the items and childs associated (at least I think so :-))
VinExpert
> And it can be done easily if U know the items and childs associated
Not as easily as just counting the position of item within the control.
..B ekiM
Not as easily as just counting the position of item within the control.
..B ekiM
ASKER
Thanks a lot VinExpert & Mikeblas !!!
-Sun307
-Sun307
U can do all the CTreeCtrl operations using the HTREEITEM, u can delete, select..., then why u need the item index?
Try it out.
VinExpert