CTreeCtrl::GetNextSiblingItem never null
-
Hello! I just want to pass through all the siblings of a parent CTreeCtrl node. So I do something like the code from msdn http://msdn.microsoft.com/en-us/library/xfh3f9zt.aspx[^]:
if (m_TreeCtrl.ItemHasChildren(hmyItem))
{
HTREEITEM hItem = m_TreeCtrl.GetChildItem(hmyItem);while (hItem != NULL)
{
hItem = m_TreeCtrl.GetNextSiblingItem(hItem);
}
}The problem is that, GetNextSiblingItem never returns null. When all the siblings are passed through and the function should return null, it just returns the first sibling. So it enters into an infinite loop. I just cannot understand why it does so.
-
Hello! I just want to pass through all the siblings of a parent CTreeCtrl node. So I do something like the code from msdn http://msdn.microsoft.com/en-us/library/xfh3f9zt.aspx[^]:
if (m_TreeCtrl.ItemHasChildren(hmyItem))
{
HTREEITEM hItem = m_TreeCtrl.GetChildItem(hmyItem);while (hItem != NULL)
{
hItem = m_TreeCtrl.GetNextSiblingItem(hItem);
}
}The problem is that, GetNextSiblingItem never returns null. When all the siblings are passed through and the function should return null, it just returns the first sibling. So it enters into an infinite loop. I just cannot understand why it does so.
-
I had used this code several time without any problem ... so, check your code again, eventually load the tree with few simple test items ...
-
I had created an dialog based project, where I put an tree control, named m_Tree, and in OnInitDialog I wrote following code:
HTREEITEM hItem = m\_Tree.InsertItem(\_T("One")); m\_Tree.InsertItem(\_T("Test1"), hItem); m\_Tree.InsertItem(\_T("Test2"), hItem); m\_Tree.InsertItem(\_T("Test3"), hItem); m\_Tree.InsertItem(\_T("Two")); m\_Tree.InsertItem(\_T("Three")); HTREEITEM hRoot = m\_Tree.GetRootItem(); if(m\_Tree.ItemHasChildren(hRoot)) { HTREEITEM hChild = m\_Tree.GetChildItem(hRoot); while(NULL != hChild) { TRACE("%s\\n", m\_Tree.GetItemText(hChild)); hChild = m\_Tree.GetNextSiblingItem(hChild); } }
which are similar with yours, and I get this:
Test1
Test2
Test3You could try it ...
-
I had created an dialog based project, where I put an tree control, named m_Tree, and in OnInitDialog I wrote following code:
HTREEITEM hItem = m\_Tree.InsertItem(\_T("One")); m\_Tree.InsertItem(\_T("Test1"), hItem); m\_Tree.InsertItem(\_T("Test2"), hItem); m\_Tree.InsertItem(\_T("Test3"), hItem); m\_Tree.InsertItem(\_T("Two")); m\_Tree.InsertItem(\_T("Three")); HTREEITEM hRoot = m\_Tree.GetRootItem(); if(m\_Tree.ItemHasChildren(hRoot)) { HTREEITEM hChild = m\_Tree.GetChildItem(hRoot); while(NULL != hChild) { TRACE("%s\\n", m\_Tree.GetItemText(hChild)); hChild = m\_Tree.GetNextSiblingItem(hChild); } }
which are similar with yours, and I get this:
Test1
Test2
Test3You could try it ...
Thanks for your answer! I know it works, because I tried another similar tree myself. But I really do not know why it does not work in a particular case. What I am trying to do is to copy a CTreeCtrl from Dialog1 to Dialog2. So I do something like Dialog1::_tree1.GetNextSiblingItem(ci) and then put ci in _tree2 which is in Dialog2, like this _tree2.InsertItem(csChild,NULL, NULL), where csChild = Dialog1::_tree1.GetItemText(ci). So it may be that this cross dialog thing is the problem.