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

CTreeCtrl Problem

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelpquestion
7 Posts 6 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.
  • _ Offline
    _ Offline
    _anil_
    wrote on last edited by
    #1

    What I am doing may be stupid. But if I want to do like this then what to do... In the doubleclick of the tree view item I delete that item. In that case the application crashed. What to do if I want to delete the item in the doubleclick. What is the reason that it is crashing.

    Regards Anil

    A S S 3 Replies Last reply
    0
    • _ _anil_

      What I am doing may be stupid. But if I want to do like this then what to do... In the doubleclick of the tree view item I delete that item. In that case the application crashed. What to do if I want to delete the item in the doubleclick. What is the reason that it is crashing.

      Regards Anil

      A Offline
      A Offline
      aquawicket
      wrote on last edited by
      #2

      Almost sounds like some still points to the item.. Gotta post some code.. ;)

      _ 1 Reply Last reply
      0
      • A aquawicket

        Almost sounds like some still points to the item.. Gotta post some code.. ;)

        _ Offline
        _ Offline
        _anil_
        wrote on last edited by
        #3

        For your reference I make the code like this... void CBackupTreeBar::OnNMDblclkBckTree(NMHDR *pNMHDR, LRESULT *pResult) { if( IsSelectFile() == TRUE ){ m_BackupTree.DeleteItem( m_BackupTree.GetRootItem() ); } *pResult = 0; } This code will crash... But If make *pResult = -1; it is working. Of course the tree items won't be there.

        Regards Anil

        M P 2 Replies Last reply
        0
        • _ _anil_

          For your reference I make the code like this... void CBackupTreeBar::OnNMDblclkBckTree(NMHDR *pNMHDR, LRESULT *pResult) { if( IsSelectFile() == TRUE ){ m_BackupTree.DeleteItem( m_BackupTree.GetRootItem() ); } *pResult = 0; } This code will crash... But If make *pResult = -1; it is working. Of course the tree items won't be there.

          Regards Anil

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          You're deleting a tree item in an event handler that is processing an event fired by that very item. Chances are, the tree control is going to do some other work after your handler returns that will involve that tree item. You could see how deleting it would be a bad idea.

          --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?

          1 Reply Last reply
          0
          • _ _anil_

            For your reference I make the code like this... void CBackupTreeBar::OnNMDblclkBckTree(NMHDR *pNMHDR, LRESULT *pResult) { if( IsSelectFile() == TRUE ){ m_BackupTree.DeleteItem( m_BackupTree.GetRootItem() ); } *pResult = 0; } This code will crash... But If make *pResult = -1; it is working. Of course the tree items won't be there.

            Regards Anil

            P Offline
            P Offline
            Parthi_Appu
            wrote on last edited by
            #5

            _anil_ wrote:

            m_BackupTree.DeleteItem( m_BackupTree.GetRootItem() );

            You are deleting the whole tree item here, is this your intension?

            _anil_ wrote:

            *pResult = 0; } This code will crash... But If make *pResult = -1; it is working.

            I'm not sure, but i think this is why your code get crashed. If you set pResult is 0, then the frame work thinks that you didn't handle this notification,so it'll proceed with its task. But you already deleted the tree items, so its crashing. If you set values other than zero then, the framework knows that you handled the notifaction and it does nothing.


            Do your Duty and Don't expect the Result

            1 Reply Last reply
            0
            • _ _anil_

              What I am doing may be stupid. But if I want to do like this then what to do... In the doubleclick of the tree view item I delete that item. In that case the application crashed. What to do if I want to delete the item in the doubleclick. What is the reason that it is crashing.

              Regards Anil

              S Offline
              S Offline
              syampj
              wrote on last edited by
              #6

              In all applications; by double clicking the tree will be expanded. You can create a context menu with a button as delete. on righ clicking on the tree or item invoke the context menu and click the delete button to delete the item. Regards, Syam

              1 Reply Last reply
              0
              • _ _anil_

                What I am doing may be stupid. But if I want to do like this then what to do... In the doubleclick of the tree view item I delete that item. In that case the application crashed. What to do if I want to delete the item in the doubleclick. What is the reason that it is crashing.

                Regards Anil

                S Offline
                S Offline
                skornel
                wrote on last edited by
                #7

                I ran into this issue about a year ago and the issue is exactly what Michael Dunn stated. And I fixed the problem the same way suggested by syampi.

                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