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. how to confirm the tree item selected

how to confirm the tree item selected

Scheduled Pinned Locked Moved C / C++ / MFC
data-structurestutorial
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.
  • T try88

    hi :-D what i mean is that if i clicked the item4 "---1。2--------" ,how to confirm i real did that in code. ----------------- 1 --1-------------- 2 ---1。1-------- 3 ---1。2-------- 4 ---1。3-------- 5 --2-------------- 6 ---2。1-------- 7 ---2。2-------- 8 ---2。3-------- 9 路漫漫其修远兮,吾将上下而求索。

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

    Are you talking about the TVN_SELCHANGED notification?


    "One must learn from the bite of the fire to leave it alone." - Native American Proverb

    T 1 Reply Last reply
    0
    • D David Crow

      Are you talking about the TVN_SELCHANGED notification?


      "One must learn from the bite of the fire to leave it alone." - Native American Proverb

      T Offline
      T Offline
      try88
      wrote on last edited by
      #3

      yes i am ,TVN_SELCHANGED or NM_CLICK you know the answer? please give a hint 路漫漫其修远兮,吾将上下而求索。

      D 1 Reply Last reply
      0
      • T try88

        hi :-D what i mean is that if i clicked the item4 "---1。2--------" ,how to confirm i real did that in code. ----------------- 1 --1-------------- 2 ---1。1-------- 3 ---1。2-------- 4 ---1。3-------- 5 --2-------------- 6 ---2。1-------- 7 ---2。2-------- 8 ---2。3-------- 9 路漫漫其修远兮,吾将上下而求索。

        M Offline
        M Offline
        Maximilien
        wrote on last edited by
        #4

        I'm not sure I understand what you want to confirm. when you click on a tree item, you will have a TVN_SELCHANGED notification ( add an handler for that ), in the handler you will receive the HTREEITEM that is selected. something like :

        void MyTree::OnTreeSelchanged( NMHDR* pNMHDR, LRESULT* pResult )
        {
        NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
        HTREEITEM item = pNMTreeView->itemNew.hItem;
        }

        if you want to check for a "hardcoded" string, CTreeCtrl::GetItemText( ... ) might be what you want to check for. otherwise, I'm not certain.


        Maximilien Lincourt Your Head A Splode - Strong Bad

        T 1 Reply Last reply
        0
        • T try88

          yes i am ,TVN_SELCHANGED or NM_CLICK you know the answer? please give a hint 路漫漫其修远兮,吾将上下而求索。

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

          See here.


          "One must learn from the bite of the fire to leave it alone." - Native American Proverb

          T 1 Reply Last reply
          0
          • M Maximilien

            I'm not sure I understand what you want to confirm. when you click on a tree item, you will have a TVN_SELCHANGED notification ( add an handler for that ), in the handler you will receive the HTREEITEM that is selected. something like :

            void MyTree::OnTreeSelchanged( NMHDR* pNMHDR, LRESULT* pResult )
            {
            NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
            HTREEITEM item = pNMTreeView->itemNew.hItem;
            }

            if you want to check for a "hardcoded" string, CTreeCtrl::GetItemText( ... ) might be what you want to check for. otherwise, I'm not certain.


            Maximilien Lincourt Your Head A Splode - Strong Bad

            T Offline
            T Offline
            try88
            wrote on last edited by
            #6

            look at this figure: ----------------- 1 --1-------------- 2 ---1。1-------- 3 ---1。2-------- 4 ---1。3-------- 5 --2-------------- 6 ---2。1-------- 7 ---2。2-------- 8 ---2。3-------- 9 you know when i click the item for example item 4 which is"---1。2--------"; the question is how can i know that i clicked the item is item4 not others by code in my function OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult) ? that means how to judge the item clicked is the one i want in code. your hint using GetItemText( ... ) maybe bot work when my item text is put dynamically,for you even not konw the exact text. 路漫漫其修远兮,吾将上下而求索。

            M D 2 Replies Last reply
            0
            • D David Crow

              See here.


              "One must learn from the bite of the fire to leave it alone." - Native American Proverb

              T Offline
              T Offline
              try88
              wrote on last edited by
              #7

              so sad it doesn't help :( 路漫漫其修远兮,吾将上下而求索。

              D 1 Reply Last reply
              0
              • T try88

                look at this figure: ----------------- 1 --1-------------- 2 ---1。1-------- 3 ---1。2-------- 4 ---1。3-------- 5 --2-------------- 6 ---2。1-------- 7 ---2。2-------- 8 ---2。3-------- 9 you know when i click the item for example item 4 which is"---1。2--------"; the question is how can i know that i clicked the item is item4 not others by code in my function OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult) ? that means how to judge the item clicked is the one i want in code. your hint using GetItemText( ... ) maybe bot work when my item text is put dynamically,for you even not konw the exact text. 路漫漫其修远兮,吾将上下而求索。

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

                try88 wrote: ...how can i know that i clicked the item is item4 not others by code... By looking at the NMTREEVIEW structure, specifically the itemNew member. try88 wrote: your hint using GetItemText( ... ) maybe bot work when my item text is put dynamically,for you even not konw the exact text. What? How else are you going to add text if not dynamically? Tree controls are not populated at design/compile time. If an item has text, that text can be retrieved via GetItemText(). Have you looked at the documentation for how this function works?


                "One must learn from the bite of the fire to leave it alone." - Native American Proverb

                1 Reply Last reply
                0
                • T try88

                  look at this figure: ----------------- 1 --1-------------- 2 ---1。1-------- 3 ---1。2-------- 4 ---1。3-------- 5 --2-------------- 6 ---2。1-------- 7 ---2。2-------- 8 ---2。3-------- 9 you know when i click the item for example item 4 which is"---1。2--------"; the question is how can i know that i clicked the item is item4 not others by code in my function OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult) ? that means how to judge the item clicked is the one i want in code. your hint using GetItemText( ... ) maybe bot work when my item text is put dynamically,for you even not konw the exact text. 路漫漫其修远兮,吾将上下而求索。

                  M Offline
                  M Offline
                  Maximilien
                  wrote on last edited by
                  #9

                  HTREEITEM item = pNMTreeView->itemNew.hItem; tells you what item you clicked on. if you add things dynamically to the tree, you will need to attach some kind of user data to each item ( or leaves ) of the tree with CTreeCtrl::SetItemData to identify it. besides, your figure it not clear at all; what is the tree data ? what is the item number ?


                  Maximilien Lincourt Your Head A Splode - Strong Bad

                  T 1 Reply Last reply
                  0
                  • T try88

                    so sad it doesn't help :( 路漫漫其修远兮,吾将上下而求索。

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

                    try88 wrote: so sad it doesn't help Why?


                    "One must learn from the bite of the fire to leave it alone." - Native American Proverb

                    1 Reply Last reply
                    0
                    • M Maximilien

                      HTREEITEM item = pNMTreeView->itemNew.hItem; tells you what item you clicked on. if you add things dynamically to the tree, you will need to attach some kind of user data to each item ( or leaves ) of the tree with CTreeCtrl::SetItemData to identify it. besides, your figure it not clear at all; what is the tree data ? what is the item number ?


                      Maximilien Lincourt Your Head A Splode - Strong Bad

                      T Offline
                      T Offline
                      try88
                      wrote on last edited by
                      #11

                      thank you !! Maximilien wrote: SetItemData to identify it is just what i searching for days! God will bless you!! thank you !! 路漫漫其修远兮,吾将上下而求索。

                      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