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. index of HTREEITEM item?

index of HTREEITEM item?

Scheduled Pinned Locked Moved C / C++ / MFC
questiondatabasehelptutorial
11 Posts 7 Posters 1 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.
  • Z zon_cpp

    hi! how do i get counter of item (index of item in CTreeCtrl) with its HTREEITEM ? for example: user selects 3th item of CTreeCtrl. in code, with GetSelectedItem() function we have HTREEITEM of item. but index of it?(in this example 3) please help me...

    Zo.Naderi-Iran

    C Offline
    C Offline
    Code o mat
    wrote on last edited by
    #2

    The index based on what? What would be index 0?

    > The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<

    1 Reply Last reply
    0
    • Z zon_cpp

      hi! how do i get counter of item (index of item in CTreeCtrl) with its HTREEITEM ? for example: user selects 3th item of CTreeCtrl. in code, with GetSelectedItem() function we have HTREEITEM of item. but index of it?(in this example 3) please help me...

      Zo.Naderi-Iran

      M Offline
      M Offline
      Madhu Nair 0
      wrote on last edited by
      #3

      The index concept is not applicable for a TreeItem. The HTREEITEM itself is an index identifier for the item. Loop through each items and store the index values and HTREEITEM in a map for future use.

      zon_cpp wrote:

      user selects 3th item of CTreeCtrl.

      If your issue is to get the exact item when the user clicks on a treeitem - I have a suggestion, to use CTreeCtrl's HitTest[^] to get the item from selected point.

      Z 1 Reply Last reply
      0
      • M Madhu Nair 0

        The index concept is not applicable for a TreeItem. The HTREEITEM itself is an index identifier for the item. Loop through each items and store the index values and HTREEITEM in a map for future use.

        zon_cpp wrote:

        user selects 3th item of CTreeCtrl.

        If your issue is to get the exact item when the user clicks on a treeitem - I have a suggestion, to use CTreeCtrl's HitTest[^] to get the item from selected point.

        Z Offline
        Z Offline
        zon_cpp
        wrote on last edited by
        #4

        when user click on item of Tree view. for example 3th item: how do i get (3) numeral index this item?

        Zo.Naderi-Iran

        S 1 Reply Last reply
        0
        • Z zon_cpp

          hi! how do i get counter of item (index of item in CTreeCtrl) with its HTREEITEM ? for example: user selects 3th item of CTreeCtrl. in code, with GetSelectedItem() function we have HTREEITEM of item. but index of it?(in this example 3) please help me...

          Zo.Naderi-Iran

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

          Why you need the actual "position" (I assume that's what you want) ? Assuming you want the position in regards with the parent node

          parent

          • node1
          • node2
          • node3 // 3rd item
          • node4

          Anyway, a suggestion : CTreeCtrl::GetParent of selected node and then use CTreeCtrl::GetChildItem and CTreeCtrl::GetNextSiblingItem(or other similar member) in a loop to get the next item; just count.

          Watched code never compiles.

          S C 2 Replies Last reply
          0
          • Z zon_cpp

            hi! how do i get counter of item (index of item in CTreeCtrl) with its HTREEITEM ? for example: user selects 3th item of CTreeCtrl. in code, with GetSelectedItem() function we have HTREEITEM of item. but index of it?(in this example 3) please help me...

            Zo.Naderi-Iran

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

            zon_cpp wrote:

            for example: user selects 3th item of CTreeCtrl.

            3rd item relative to what?

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather

            1 Reply Last reply
            0
            • Z zon_cpp

              hi! how do i get counter of item (index of item in CTreeCtrl) with its HTREEITEM ? for example: user selects 3th item of CTreeCtrl. in code, with GetSelectedItem() function we have HTREEITEM of item. but index of it?(in this example 3) please help me...

              Zo.Naderi-Iran

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

              One way: you can pass index in LPARAM lParam argument when inserting items in treeview; then use GetSelectedItem to get handle to selected tree item and get it index with CTreeCtrl::GetItem .

              HTREEITEM hItem = m_treeFeature.GetSelectedItem();
              TVITEM tvItem = {0};
              tvItem.mask = TVIF_PARAM;
              tvItem.hItem = hItem;
              m_treeFeature.GetItem(&tvItem);
              int nindex = (int)tvItem.lParam;

              HTREEITEM GetSelectedItem( ) http://msdn.microsoft.com/en-us/library/xw6h5d91(v=vs.80).aspx[^]

              1 Reply Last reply
              0
              • Z zon_cpp

                when user click on item of Tree view. for example 3th item: how do i get (3) numeral index this item?

                Zo.Naderi-Iran

                S Offline
                S Offline
                Stefan_Lang
                wrote on last edited by
                #8

                You don't. A Tree does not have or use an index. Even if it had, the moment an item gets removed or added, any stored index values would all be invalidated - so you cannot store an index and hope to later retrieve the correct item through that index, because it might no longer be valid! The HTREEITEM value you get is what is generally called a 'handle'. It serves as a reference to the actual item, and it will remain valid until this child item is removed from the tree. You should use that handle and retrieve the child item, using HTREEITEM GetChildItem(HTREEITEM hItem) const; (see http://msdn.microsoft.com/en-US/library/yk3ystd6%28v=VS.80%29.aspx[^]).

                1 Reply Last reply
                0
                • M Maximilien

                  Why you need the actual "position" (I assume that's what you want) ? Assuming you want the position in regards with the parent node

                  parent

                  • node1
                  • node2
                  • node3 // 3rd item
                  • node4

                  Anyway, a suggestion : CTreeCtrl::GetParent of selected node and then use CTreeCtrl::GetChildItem and CTreeCtrl::GetNextSiblingItem(or other similar member) in a loop to get the next item; just count.

                  Watched code never compiles.

                  S Offline
                  S Offline
                  Stefan_Lang
                  wrote on last edited by
                  #9

                  Good idea, and it actually answers the question - but I wonder whether that's what he (or she) actually needs ;)

                  1 Reply Last reply
                  0
                  • M Maximilien

                    Why you need the actual "position" (I assume that's what you want) ? Assuming you want the position in regards with the parent node

                    parent

                    • node1
                    • node2
                    • node3 // 3rd item
                    • node4

                    Anyway, a suggestion : CTreeCtrl::GetParent of selected node and then use CTreeCtrl::GetChildItem and CTreeCtrl::GetNextSiblingItem(or other similar member) in a loop to get the next item; just count.

                    Watched code never compiles.

                    C Offline
                    C Offline
                    Code o mat
                    wrote on last edited by
                    #10

                    Wouldn't calling GetPrevSiblingItem[^] to walk "upwards" until it returns no more items and counting that work?

                    > The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<

                    M 1 Reply Last reply
                    0
                    • C Code o mat

                      Wouldn't calling GetPrevSiblingItem[^] to walk "upwards" until it returns no more items and counting that work?

                      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > If it doesn't matter, it's antimatter.<

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

                      probably.

                      Watched code never compiles.

                      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