index of HTREEITEM item?
-
hi! how do i get counter of item (index of item in CTreeCtrl) with its HTREEITEM ? for example: user selects 3th item of CTreeCtrl. in code, with GetSelectedItem() function we have HTREEITEM of item. but index of it?(in this example 3) please help me...
Zo.Naderi-Iran
-
hi! how do i get counter of item (index of item in CTreeCtrl) with its HTREEITEM ? for example: user selects 3th item of CTreeCtrl. in code, with GetSelectedItem() function we have HTREEITEM of item. but index of it?(in this example 3) please help me...
Zo.Naderi-Iran
The index based on what? What would be index 0?
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<
-
hi! how do i get counter of item (index of item in CTreeCtrl) with its HTREEITEM ? for example: user selects 3th item of CTreeCtrl. in code, with GetSelectedItem() function we have HTREEITEM of item. but index of it?(in this example 3) please help me...
Zo.Naderi-Iran
The index concept is not applicable for a TreeItem. The HTREEITEM itself is an index identifier for the item. Loop through each items and store the index values and HTREEITEM in a map for future use.
zon_cpp wrote:
user selects 3th item of CTreeCtrl.
If your issue is to get the exact item when the user clicks on a treeitem - I have a suggestion, to use CTreeCtrl's HitTest[^] to get the item from selected point.
-
The index concept is not applicable for a TreeItem. The HTREEITEM itself is an index identifier for the item. Loop through each items and store the index values and HTREEITEM in a map for future use.
zon_cpp wrote:
user selects 3th item of CTreeCtrl.
If your issue is to get the exact item when the user clicks on a treeitem - I have a suggestion, to use CTreeCtrl's HitTest[^] to get the item from selected point.
-
hi! how do i get counter of item (index of item in CTreeCtrl) with its HTREEITEM ? for example: user selects 3th item of CTreeCtrl. in code, with GetSelectedItem() function we have HTREEITEM of item. but index of it?(in this example 3) please help me...
Zo.Naderi-Iran
Why you need the actual "position" (I assume that's what you want) ? Assuming you want the position in regards with the parent node
parent
- node1
- node2
- node3 // 3rd item
- node4
Anyway, a suggestion :
CTreeCtrl::GetParent
of selected node and then useCTreeCtrl::GetChildItem
andCTreeCtrl::GetNextSiblingItem
(or other similar member) in a loop to get the next item; just count.Watched code never compiles.
-
hi! how do i get counter of item (index of item in CTreeCtrl) with its HTREEITEM ? for example: user selects 3th item of CTreeCtrl. in code, with GetSelectedItem() function we have HTREEITEM of item. but index of it?(in this example 3) please help me...
Zo.Naderi-Iran
zon_cpp wrote:
for example: user selects 3th item of CTreeCtrl.
3rd item relative to what?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
-
hi! how do i get counter of item (index of item in CTreeCtrl) with its HTREEITEM ? for example: user selects 3th item of CTreeCtrl. in code, with GetSelectedItem() function we have HTREEITEM of item. but index of it?(in this example 3) please help me...
Zo.Naderi-Iran
One way: you can pass index in LPARAM lParam argument when inserting items in treeview; then use GetSelectedItem to get handle to selected tree item and get it index with CTreeCtrl::GetItem .
HTREEITEM hItem = m_treeFeature.GetSelectedItem();
TVITEM tvItem = {0};
tvItem.mask = TVIF_PARAM;
tvItem.hItem = hItem;
m_treeFeature.GetItem(&tvItem);
int nindex = (int)tvItem.lParam;HTREEITEM GetSelectedItem( ) http://msdn.microsoft.com/en-us/library/xw6h5d91(v=vs.80).aspx[^]
-
when user click on item of Tree view. for example 3th item: how do i get (3) numeral index this item?
Zo.Naderi-Iran
You don't. A Tree does not have or use an index. Even if it had, the moment an item gets removed or added, any stored index values would all be invalidated - so you cannot store an index and hope to later retrieve the correct item through that index, because it might no longer be valid! The HTREEITEM value you get is what is generally called a 'handle'. It serves as a reference to the actual item, and it will remain valid until this child item is removed from the tree. You should use that handle and retrieve the child item, using
HTREEITEM GetChildItem(HTREEITEM hItem) const;
(see http://msdn.microsoft.com/en-US/library/yk3ystd6%28v=VS.80%29.aspx[^]). -
Why you need the actual "position" (I assume that's what you want) ? Assuming you want the position in regards with the parent node
parent
- node1
- node2
- node3 // 3rd item
- node4
Anyway, a suggestion :
CTreeCtrl::GetParent
of selected node and then useCTreeCtrl::GetChildItem
andCTreeCtrl::GetNextSiblingItem
(or other similar member) in a loop to get the next item; just count.Watched code never compiles.
Good idea, and it actually answers the question - but I wonder whether that's what he (or she) actually needs ;)
-
Why you need the actual "position" (I assume that's what you want) ? Assuming you want the position in regards with the parent node
parent
- node1
- node2
- node3 // 3rd item
- node4
Anyway, a suggestion :
CTreeCtrl::GetParent
of selected node and then useCTreeCtrl::GetChildItem
andCTreeCtrl::GetNextSiblingItem
(or other similar member) in a loop to get the next item; just count.Watched code never compiles.
Wouldn't calling GetPrevSiblingItem[^] to walk "upwards" until it returns no more items and counting that work?
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<
-
Wouldn't calling GetPrevSiblingItem[^] to walk "upwards" until it returns no more items and counting that work?
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<
probably.
Watched code never compiles.