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 problem in MFC

CTreeCtrl problem in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structureshelpquestion
5 Posts 3 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.
  • N Offline
    N Offline
    nbugalia
    wrote on last edited by
    #1

    The function ItemHasChildren (TreeItem) returns true for a perticular node but GetChildItem (TreeItem) doesnot return a valid node without expanding the node TreeItem. This expanding and shrinking is causing flicker in the tree. Could anyone provide a better solution ? The sample code is following -

        if (ItemHasChildren (TreeItem))
         {
            HTREEITEM tmpTreeItem = TreeItem;
            Expand (tmpTreeItem, TVE\_TOGGLE); //Causing flicker
    
            TreeItem = GetChildItem (TreeItem);
            Expand (tmpTreeItem, TVE\_TOGGLE); //Causing flicker
         }
    
    J I 2 Replies Last reply
    0
    • N nbugalia

      The function ItemHasChildren (TreeItem) returns true for a perticular node but GetChildItem (TreeItem) doesnot return a valid node without expanding the node TreeItem. This expanding and shrinking is causing flicker in the tree. Could anyone provide a better solution ? The sample code is following -

          if (ItemHasChildren (TreeItem))
           {
              HTREEITEM tmpTreeItem = TreeItem;
              Expand (tmpTreeItem, TVE\_TOGGLE); //Causing flicker
      
              TreeItem = GetChildItem (TreeItem);
              Expand (tmpTreeItem, TVE\_TOGGLE); //Causing flicker
           }
      
      J Offline
      J Offline
      jhwurmbach
      wrote on last edited by
      #2

      NishantB++ wrote:

      expanding and shrinking is causing flicker in the tree.

      Stop the tree from redrawing while you are tampering with it. From my CTreeView I do: GetTreeCtrl().SetRedraw( FALSE); ... GetTreeCtrl().SetRedraw( TRUE);


      Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
      Douglas Adams, "Dirk Gently's Holistic Detective Agency"

      N 1 Reply Last reply
      0
      • J jhwurmbach

        NishantB++ wrote:

        expanding and shrinking is causing flicker in the tree.

        Stop the tree from redrawing while you are tampering with it. From my CTreeView I do: GetTreeCtrl().SetRedraw( FALSE); ... GetTreeCtrl().SetRedraw( TRUE);


        Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
        Douglas Adams, "Dirk Gently's Holistic Detective Agency"

        N Offline
        N Offline
        nbugalia
        wrote on last edited by
        #3

        Thanks for your reply. I have already tried this option, and it is not working. By the way, have you seen this kind of behaviour that you have to expand the tree first to get the child node, or I am doing something wrong?

        J 1 Reply Last reply
        0
        • N nbugalia

          Thanks for your reply. I have already tried this option, and it is not working. By the way, have you seen this kind of behaviour that you have to expand the tree first to get the child node, or I am doing something wrong?

          J Offline
          J Offline
          jhwurmbach
          wrote on last edited by
          #4

          NishantB++ wrote:

          expand the tree first to get the child node

          I have. But then I use CWaitingTreeCtrl from Codeproject[^], and there things are much more complicated. It might really be that the item does not know that it has children and how many of them.


          Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
          Douglas Adams, "Dirk Gently's Holistic Detective Agency"

          1 Reply Last reply
          0
          • N nbugalia

            The function ItemHasChildren (TreeItem) returns true for a perticular node but GetChildItem (TreeItem) doesnot return a valid node without expanding the node TreeItem. This expanding and shrinking is causing flicker in the tree. Could anyone provide a better solution ? The sample code is following -

                if (ItemHasChildren (TreeItem))
                 {
                    HTREEITEM tmpTreeItem = TreeItem;
                    Expand (tmpTreeItem, TVE\_TOGGLE); //Causing flicker
            
                    TreeItem = GetChildItem (TreeItem);
                    Expand (tmpTreeItem, TVE\_TOGGLE); //Causing flicker
                 }
            
            I Offline
            I Offline
            Iain Clarke Warrior Programmer
            wrote on last edited by
            #5

            The below code is from MSDN. While their samples can be lacking sometimes, they're not usually wrong.

            if (pmyTreeCtrl->ItemHasChildren(hmyItem))
            {
            HTREEITEM hNextItem;
            HTREEITEM hChildItem = pmyTreeCtrl->GetChildItem(hmyItem);

            while (hChildItem != NULL)
            {
            hNextItem = pmyTreeCtrl->GetNextItem(hChildItem, TVGN_NEXT);
            pmyTreeCtrl->DeleteItem(hChildItem);
            hChildItem = hNextItem;
            }
            }

            The only thing I can think of that may mess it up is if your parent item does not actually have children in it, but you've manually set its item.cChildren to I_CHILDRENCALLBACK. Can you check the return value from ItemHasChildren to make sure it's 0 or 1? Iain.

            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