Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I iterate through ALL items in a CTreeCtrl?

4,501 views
Skip to first unread message

Mediaright Technology, Inc.

unread,
Aug 12, 1997, 3:00:00 AM8/12/97
to

Hey there,

How can I iterate through ALL items in a CTreeCtrl? I have multiple items
at the root level. I seem only to be able to loop through one sub tree off
of the root. What I really want to do is fully expand all node in the tree.

The following code almost does what I want but not quite:
if (hti = treeCtrl.GetRootItem())
{
while (hti = treeCtrl.GetNextItem(hti,TVGN_NEXT))
treeCtrl.Expand(hti,TVE_EXPAND) ;
}

Thanks in Advance,

Craig Klementowski
cr...@mediaright.com

Martin Vogel

unread,
Aug 14, 1997, 3:00:00 AM8/14/97
to

You can add i.e. checking of children for each level:

list of all children for one level:
if (GetTreeCtrl().ItemHasChildren(hRootItem))
{
hItem = GetTreeCtrl().GetChildItem(hRootDevice);
...
while (hItem = GetTreeCtrl().GetNextItem(hItem,TVGN_NEXT))
...
}

Mediaright Technology, Inc. wrote in article
<01bca740$ecd8ada0$dba562ce@mercer>...

mthog...@luminous.com

unread,
Aug 18, 1997, 3:00:00 AM8/18/97
to Mediaright Technology, Inc.

Mediaright Technology, Inc. wrote:
>
> Hey there,
>
> How can I iterate through ALL items in a CTreeCtrl? I have multiple items
> at the root level. I seem only to be able to loop through one sub tree off
> of the root. What I really want to do is fully expand all node in the tree.
>
> The following code almost does what I want but not quite:
> if (hti = treeCtrl.GetRootItem())
> {
> while (hti = treeCtrl.GetNextItem(hti,TVGN_NEXT))
> treeCtrl.Expand(hti,TVE_EXPAND) ;
> }
>
> Thanks in Advance,
>
> Craig Klementowski
> cr...@mediaright.com

Recursive functions work great for this kind of thing.

void ExpandAll(HTREEITEM hItemParent)
{
HTREEITEM childItem;
if(GetTreeCtrl().ItemHasChildren(hItemParent){
GetTreeCtrl().Expand(hItemParent);
for(childItem = GetTreeCtrl().GetChildItem(childItem);childItem !=
NULL;
childItem = GetTreeCtrl().GetNextItem(childItem, TVGN_NEXT))
ExpandAll(childItem);
}
}

Zafir Anjum

unread,
Aug 18, 1997, 3:00:00 AM8/18/97
to mthog...@luminous.com

Visit http://www.dsp.com/zafir for tree traversal code.
There's code for forward as well as reverse traversal,
and you don't have to expand the branch if you don't
want to.

-Zafir

0 new messages