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. Problem with CTreeCtrl::DeleteAllItems

Problem with CTreeCtrl::DeleteAllItems

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structureshelptutorialquestion
6 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.
  • S Offline
    S Offline
    Stlan
    wrote on last edited by
    #1

    I have a strange problem with CTreeCtrl::DeleteAllItems under VS2003: it seems impossible to insert a new tree item after having called this function. Let's try a simple example: - Create a new MFC dialog application, - Add a tree control in the dialog, - Associate a CTreeCtrl variable with it, - in the OnInitDialog, add the code: c_Tree.InsertItem(_T("Item before")); c_Tree.DeleteAllItems(); c_Tree.InsertItem(_T("Item after")); When executing the prg, the control remains empty. However, if I comment the call to DeleteAllItems, I see two items as expected. X| Has anybody already experimented this ?

    A 1 Reply Last reply
    0
    • S Stlan

      I have a strange problem with CTreeCtrl::DeleteAllItems under VS2003: it seems impossible to insert a new tree item after having called this function. Let's try a simple example: - Create a new MFC dialog application, - Add a tree control in the dialog, - Associate a CTreeCtrl variable with it, - in the OnInitDialog, add the code: c_Tree.InsertItem(_T("Item before")); c_Tree.DeleteAllItems(); c_Tree.InsertItem(_T("Item after")); When executing the prg, the control remains empty. However, if I comment the call to DeleteAllItems, I see two items as expected. X| Has anybody already experimented this ?

      A Offline
      A Offline
      Arjan Schouten
      wrote on last edited by
      #2

      Just a quess but try adding a UpdateData(FALSE); after the last InsertItem Arjan

      S 1 Reply Last reply
      0
      • A Arjan Schouten

        Just a quess but try adding a UpdateData(FALSE); after the last InsertItem Arjan

        S Offline
        S Offline
        Stlan
        wrote on last edited by
        #3

        I doesn't change anything because UpdateData usually validates DDX data and not DDX controls. However, insertions work perfectly as long as I do not use DeleteAllItems. As soon it is called, no further insertions are possible (ie. InsertItem returns a valid HTREEITEM handle, but the tree control client area remains empty, even if I force the control to redraw.) Looks like DeleteAllItems makes a real mess in the control! :confused:

        A 1 Reply Last reply
        0
        • S Stlan

          I doesn't change anything because UpdateData usually validates DDX data and not DDX controls. However, insertions work perfectly as long as I do not use DeleteAllItems. As soon it is called, no further insertions are possible (ie. InsertItem returns a valid HTREEITEM handle, but the tree control client area remains empty, even if I force the control to redraw.) Looks like DeleteAllItems makes a real mess in the control! :confused:

          A Offline
          A Offline
          Arjan Schouten
          wrote on last edited by
          #4

          You're right this is a bug! But you can workaround it. m_cTree.InsertItem("Before"); m_cTree.SetRedraw(FALSE); m_cTree.DeleteAllItems(); m_cTree.InsertItem("after"); m_cTree.SetRedraw(TRUE); or just set the tree's scroll property to true. Arjan

          S A 2 Replies Last reply
          0
          • A Arjan Schouten

            You're right this is a bug! But you can workaround it. m_cTree.InsertItem("Before"); m_cTree.SetRedraw(FALSE); m_cTree.DeleteAllItems(); m_cTree.InsertItem("after"); m_cTree.SetRedraw(TRUE); or just set the tree's scroll property to true. Arjan

            S Offline
            S Offline
            Stlan
            wrote on last edited by
            #5

            Thank you, Arjan for the workarounds! :rose:

            1 Reply Last reply
            0
            • A Arjan Schouten

              You're right this is a bug! But you can workaround it. m_cTree.InsertItem("Before"); m_cTree.SetRedraw(FALSE); m_cTree.DeleteAllItems(); m_cTree.InsertItem("after"); m_cTree.SetRedraw(TRUE); or just set the tree's scroll property to true. Arjan

              A Offline
              A Offline
              Al Forno
              wrote on last edited by
              #6

              You just saved me from going crazy over this. Thanks!!!

              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