Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CTreeCtrl::GetNextSiblingItem never null

CTreeCtrl::GetNextSiblingItem never null

Scheduled Pinned Locked Moved C / C++ / MFC
comhelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dliviu
    wrote on last edited by
    #1

    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.

    _ 1 Reply Last reply
    0
    • D dliviu

      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.

      _ Offline
      _ Offline
      _Flaviu
      wrote on last edited by
      #2

      I had used this code several time without any problem ... so, check your code again, eventually load the tree with few simple test items ...

      D 1 Reply Last reply
      0
      • _ _Flaviu

        I had used this code several time without any problem ... so, check your code again, eventually load the tree with few simple test items ...

        D Offline
        D Offline
        dliviu
        wrote on last edited by
        #3

        OK, thanks.

        _ 1 Reply Last reply
        0
        • D dliviu

          OK, thanks.

          _ Offline
          _ Offline
          _Flaviu
          wrote on last edited by
          #4

          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
          Test3

          You could try it ...

          D 1 Reply Last reply
          0
          • _ _Flaviu

            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
            Test3

            You could try it ...

            D Offline
            D Offline
            dliviu
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups