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. trouble in inserting data to tree control

trouble in inserting data to tree control

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++data-structureshelp
11 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.
  • F firebolt77

    Hi..I want to insert a item to an existing tree and I want to make the item become the child of one of the tree members for example: before: root ..|_parent1 ..|_parent2 ..|_parent3 after: root ..|_parent1 ..|_parent2 ......|_(I want to insert my new item in here) ..|_parent3 but I didn't know how to do it. Plz help me because I'm a newbie in MFC programming thx.

    M Offline
    M Offline
    Marc Soleda
    wrote on last edited by
    #2

    m_treeCtrl.InsertItem. From MSDN: HTREEITEM InsertItem( LPTVINSERTSTRUCT lpInsertStruct ); HTREEITEM InsertItem(UINT nMask, LPCTSTR lpszItem, int nImage, int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam, HTREEITEM hParent, HTREEITEM hInsertAfter ); Download this project[^], you'll find it usefull. Marc Soleda. ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.

    1 Reply Last reply
    0
    • F firebolt77

      Hi..I want to insert a item to an existing tree and I want to make the item become the child of one of the tree members for example: before: root ..|_parent1 ..|_parent2 ..|_parent3 after: root ..|_parent1 ..|_parent2 ......|_(I want to insert my new item in here) ..|_parent3 but I didn't know how to do it. Plz help me because I'm a newbie in MFC programming thx.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #3

      Call CTreeCtrl::GetItem() on the "parent2" item. Then call CTreeCtrl::InsertItem() to insert the new "child" item below that.


      "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

      F 1 Reply Last reply
      0
      • D David Crow

        Call CTreeCtrl::GetItem() on the "parent2" item. Then call CTreeCtrl::InsertItem() to insert the new "child" item below that.


        "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

        F Offline
        F Offline
        firebolt77
        wrote on last edited by
        #4

        thx 2 you all for your help. Can a tree control access another atttributes of a data? I am planning to make a tree control from a list of data for example, I am a list of datas, each of data consists of Name, adrress, phone number, etc and I want to make the tree control based on the name. Does it exist any command to access/ display other attributes by clicking the tree element? thx..

        D 1 Reply Last reply
        0
        • F firebolt77

          thx 2 you all for your help. Can a tree control access another atttributes of a data? I am planning to make a tree control from a list of data for example, I am a list of datas, each of data consists of Name, adrress, phone number, etc and I want to make the tree control based on the name. Does it exist any command to access/ display other attributes by clicking the tree element? thx..

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #5

          After inserting a node in the tree control, use SetItemData() to associate that node with the item in the list.


          "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

          F 1 Reply Last reply
          0
          • D David Crow

            After inserting a node in the tree control, use SetItemData() to associate that node with the item in the list.


            "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

            F Offline
            F Offline
            firebolt77
            wrote on last edited by
            #6

            Can u give me some examples pls?because I'm still new in MFC and lack of experience in programming. thx

            D 1 Reply Last reply
            0
            • F firebolt77

              Can u give me some examples pls?because I'm still new in MFC and lack of experience in programming. thx

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #7

              http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_ctreectrl.3a3a.setitemdata.asp[^] In your case, the second parameter to SetItemData() would be an item in your data structure.


              "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

              F 1 Reply Last reply
              0
              • D David Crow

                http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_ctreectrl.3a3a.setitemdata.asp[^] In your case, the second parameter to SetItemData() would be an item in your data structure.


                "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

                F Offline
                F Offline
                firebolt77
                wrote on last edited by
                #8

                thx...I have read the link u gave me, but I think it is not what I' looking for for example I have a data base file that consist name,age,address,phone number,etc and I want to make a tree control based on the name for example. And then if I click the tree control attributes, I can access the other database attributes such as the age,address,phone,etc. Is there any function or maybe some links to help me..because I'm so confused. thx...

                D 1 Reply Last reply
                0
                • F firebolt77

                  thx...I have read the link u gave me, but I think it is not what I' looking for for example I have a data base file that consist name,age,address,phone number,etc and I want to make a tree control based on the name for example. And then if I click the tree control attributes, I can access the other database attributes such as the age,address,phone,etc. Is there any function or maybe some links to help me..because I'm so confused. thx...

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #9

                  One way would be to read the records from the database into a data structure and populate the tree control from that data structure.


                  "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

                  F 1 Reply Last reply
                  0
                  • D David Crow

                    One way would be to read the records from the database into a data structure and populate the tree control from that data structure.


                    "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

                    F Offline
                    F Offline
                    firebolt77
                    wrote on last edited by
                    #10

                    thx...I also have some problem on populating the tree control. I want to group the tree attributes if there are same occurences. I have tried to make the function, but when I run it, my program become not responding. here is my function: HTREEITEM CCDBMainDlg::LoadTree(CStringArray& tree) { m_hItem = m_treeCDB.GetNextItem(m_hItem,TVGN_ROOT); if(m_treeCDB.ItemHasChildren(m_hItem)) { m_hItem = m_treeCDB.GetChildItem(m_hItem); while(m_treeCDB.GetItemText(m_hItem).Compare(tree.GetAt(12))!=NULL || m_hItem != NULL) { m_hItem = m_treeCDB.GetNextSiblingItem(m_hItem); } if(m_treeCDB.ItemHasChildren(m_hItem)) { m_hItem = m_treeCDB.GetChildItem(m_hItem); while(m_treeCDB.GetItemText(m_hItem).Compare(tree.GetAt(11))!=NULL || m_hItem != NULL) { m_hItem = m_treeCDB.GetNextSiblingItem(m_hItem); } if(m_treeCDB.ItemHasChildren(m_hItem)) { m_hItem = m_treeCDB.GetChildItem(m_hItem); while(m_treeCDB.GetItemText(m_hItem).Compare(tree.GetAt(0))!=NULL || m_hItem != NULL) { m_hItem = m_treeCDB.GetNextSiblingItem(m_hItem); } } else { m_hItem = m_treeCDB.InsertItem(tree.GetAt(0),0,1,m_hItem); } } else { m_hItem = m_treeCDB.InsertItem(tree.GetAt(11),0,1,m_hItem); m_hItem = m_treeCDB.InsertItem(tree.GetAt(0),0,1,m_hItem); } } else { m_hItem = m_treeCDB.InsertItem(tree.GetAt(12),0,1,m_hItem); m_hItem = m_treeCDB.InsertItem(tree.GetAt(11),0,1,m_hItem); m_hItem = m_treeCDB.InsertItem(tree.GetAt(0),0,1,m_hItem); } m_hItem = m_treeCDB.InsertItem(tree.GetAt(1),0,1,m_hItem); m_treeCDB.EnsureVisible(m_hItem); return m_hItem; } pls help. thx.

                    D 1 Reply Last reply
                    0
                    • F firebolt77

                      thx...I also have some problem on populating the tree control. I want to group the tree attributes if there are same occurences. I have tried to make the function, but when I run it, my program become not responding. here is my function: HTREEITEM CCDBMainDlg::LoadTree(CStringArray& tree) { m_hItem = m_treeCDB.GetNextItem(m_hItem,TVGN_ROOT); if(m_treeCDB.ItemHasChildren(m_hItem)) { m_hItem = m_treeCDB.GetChildItem(m_hItem); while(m_treeCDB.GetItemText(m_hItem).Compare(tree.GetAt(12))!=NULL || m_hItem != NULL) { m_hItem = m_treeCDB.GetNextSiblingItem(m_hItem); } if(m_treeCDB.ItemHasChildren(m_hItem)) { m_hItem = m_treeCDB.GetChildItem(m_hItem); while(m_treeCDB.GetItemText(m_hItem).Compare(tree.GetAt(11))!=NULL || m_hItem != NULL) { m_hItem = m_treeCDB.GetNextSiblingItem(m_hItem); } if(m_treeCDB.ItemHasChildren(m_hItem)) { m_hItem = m_treeCDB.GetChildItem(m_hItem); while(m_treeCDB.GetItemText(m_hItem).Compare(tree.GetAt(0))!=NULL || m_hItem != NULL) { m_hItem = m_treeCDB.GetNextSiblingItem(m_hItem); } } else { m_hItem = m_treeCDB.InsertItem(tree.GetAt(0),0,1,m_hItem); } } else { m_hItem = m_treeCDB.InsertItem(tree.GetAt(11),0,1,m_hItem); m_hItem = m_treeCDB.InsertItem(tree.GetAt(0),0,1,m_hItem); } } else { m_hItem = m_treeCDB.InsertItem(tree.GetAt(12),0,1,m_hItem); m_hItem = m_treeCDB.InsertItem(tree.GetAt(11),0,1,m_hItem); m_hItem = m_treeCDB.InsertItem(tree.GetAt(0),0,1,m_hItem); } m_hItem = m_treeCDB.InsertItem(tree.GetAt(1),0,1,m_hItem); m_treeCDB.EnsureVisible(m_hItem); return m_hItem; } pls help. thx.

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #11

                      firebolt77 wrote: ...but when I run it, my program become not responding. One of the while loops is not ending. You'll need to set a breakpoint on each one, run the program using F5, and note which breakpoint was not hit. That'll tell you which loop is faulty.


                      "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

                      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