Re: Traversing shallow CTreeCtrl
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Tue, 09 May 2006 13:27:45 -0400
I get a little scared when I see three variables here. Why not write a recursive function
that takes exactly on HTREEITEM
void CMyClass::Traverse(HTREEITEM item)
{
if(MyTree.ItemHasChildren(item))
{ /* iterate over children */
HTREEITEM subitem = MyTree.GetNextItem(item, TVGN_CHILD);
while(subitem != NULL)
{ /* recur */
Traverse(subitem);
subitem = MyTree.GetNextItem(subitem, TVGN_NEXT);
} /* recur */
} /* iterate over children */
}
invoke your traversal by doing:
Traverse(MyTree.GetRootItem());
To accumulate the information, you might pass in a refernce to a CArray or other suitable
data structure that you want to fill with the information you discover. Using a fixed
number of levels usually ends up being more difficult than a simple recursion.
joe
On 9 May 2006 02:50:01 -0700, msandler@xxxxxxxxxxxxxxxxxxx wrote:
I have succesfully loaded my CTreeCtrl in my dialog with hierarchicalJoseph M. Newcomer [MVP]
data. I want the user to check off the boxes next to the data he wants,
and then when he clicks OK to compile a CList of that data to be acted
apon.
The data is only three levels deep (excluding the root), and only the
2nd and 3rd levels of data are significant when checked.
I am having trouble traversing the tree. As near as I can see
GetNextItem is not returning the next child. I haven't used a recursive
function because the tree is so shallow,and I need to know what level
of data I'm for compiling the CList.
HTREEITEM Root, LvlOneNode, LvlTwoNode, LvlThreeNode;
Root = MyTree.GetRootItem();
LvlOneNode = MyTree.GetNextItem(NULL, TVGN_CHILD);
while (LvlOneNode != NULL)
{
LvlTwoNode = MyTree.GetNextItem(NULL, TVGN_CHILD);
while (LvlTwoNode != NULL)
{
if (MyTree.ItemHasChildren(LvlTwoNode))
{
LvlThreeNode = MyTree.GetNextItem(NULL, TVGN_CHILD);
while (LvlThreeNode != NULL)
{
if (MyTree.GetCheck(LvlThreeNode))
{
SelectedLvlThree.AddHead((LvlThreeData*)(MyTree.GetItemData(LvlThreeNode)));
}
LvlThreeNode = MyTree.GetNextItem(LvlThreeNode, TVGN_NEXT);
}
}
else
{
if (MyTree.GetCheck(LvlTwoNode))
{
SelectedLvlTwo.AddHead((LvlTwoData*)(MyTree.GetItemData(LvlTwoNode)));
}
}
LvlTwoNode = MyTree.GetNextItem(LvlTwoNode, TVGN_NEXT);
}
LvlOneNode = MyTree.GetNextItem(LvlOneNode, TVGN_NEXT);
}
Thanks for any advice.
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
--
NewsGuy.Com 30Gb $9.95 Carry Forward and On Demand Bandwidth
.
- References:
- Traversing shallow CTreeCtrl
- From: msandler
- Traversing shallow CTreeCtrl
- Prev by Date: Re: Still the same: CAsyncSocket::Receive and CAsyncSocket's threading
- Next by Date: Re: error LNK2001: unresolved external symbol "long __cdecl _com_dispatch_method(struct IDispatch *,long,unsigned short,unsigned short,void *,wchar_t const *,...)" (?_com_dispatch_method@@YAJPAUIDispatch@@JGGPAXPB_WZZ)
- Previous by thread: Traversing shallow CTreeCtrl
- Next by thread: capture all the Notification on a perticular windows
- Index(es):
Relevant Pages
|