Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
How can I traverse a CTreecntrl CTreeCtrl tree and save it in a structure type vector?
Posted
Updated 21-Feb-18 23:21pm
v3
Comments
fjdiewornncalwe 22-Dec-10 10:55am    
How about you try googling this first. I got over 12,000 results using a simple "CTreeCtrl to vector" search.
Manfred Rudolf Bihy 22-Dec-10 13:52pm    
Since I'm the kind of guy who likes to have options, I would pick either "depth first search" or "breadth first search". I'm not sure though if the CTreecntrl class would allow for both.

Ok! Now you've done it, you made me curious. I think I'll have to go and look that up.
Manfred Rudolf Bihy 22-Dec-10 13:54pm    
Ok. so you can't even type a simple class name. Let me fix that for you... Done!.
Manfred Rudolf Bihy 22-Dec-10 14:13pm    
Edited typo, conciser title, added algorithm tag.

5 minutes research brought forth this:

http://www.codeguru.com/forum/archive/index.php/t-359096.html

and this:

http://www.ms-news.net/f3291/traversing-ctreectrl-structure-2705009.html

This one is right from the source as they say:
http://msdn.microsoft.com/en-us/library/8bkz91b4(v=vs.80).aspx

But wait there's more: I just found out that CTreeCtrl as a method called CTreeCtrl::GetNextSiblingItem and CTreeCtrl::GetNextItem which means you can do a depth first search or a breadth first search.

Have fun!

Cheers,

Manfred
 
Share this answer
 
v3
HTREEITEM hItem = GetRootItem();
while (NULL != hItem)
{
    //TODO: Do what you want to the hItem here
    hItem = GetNextSiblingItem(hItem);
}
 
Share this answer
 
Comments
Richard MacCutchan 22-Feb-18 5:33am    
More than SEVEN years too late.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900