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 in MFC

CTreeCtrl in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++data-structurestutorialcareer
3 Posts 2 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.
  • L Offline
    L Offline
    Larry Mills Sr
    wrote on last edited by
    #1

    I have a CTreeCtrl defined in my header with a instance of m_cTree.   Here's a brief description of how the Tree looks:    [+]   Reports   (main Heading)             [+]Construction (child of Reports)                   [+] Materials (child of Construction)                            Materials Report.txt(the ".txt" is only to show you this is the actual report)             [+]Maintenance (child of Reports)                            Maintenance Report.txt(the ".txt" is only to show you this is the actual report)                   [+] Cost (child of Maintenance)             [+]Exspenses (child of Reports)                   [+] Job Cost (child of Exspenses)                            Exspenses Report.txt(the ".txt" is only to show you this is the actual report) ======================= end of example   ====================== In OnNM_ClickTreeCtrl() I cannot get the reports using this:      HTREEITEM hItem= m_cTree.GetSelectedItem();             HTREEITEM hChildItem = m_cTree.GetChildItem(hItem);             CString sSelText= m_cTree.GetItemText( hItem ); What is returns is whatever is selected including the button("[+]", the main heading, each child and finally the report.   How do I only receive the click on the Reports themselves, not all the headings? PLEASE use my example in your explaination, WITH(please) the appropriate code. Thanks in advance.

    A C++ programming language novice, but striving to learn

    N 1 Reply Last reply
    0
    • L Larry Mills Sr

      I have a CTreeCtrl defined in my header with a instance of m_cTree.   Here's a brief description of how the Tree looks:    [+]   Reports   (main Heading)             [+]Construction (child of Reports)                   [+] Materials (child of Construction)                            Materials Report.txt(the ".txt" is only to show you this is the actual report)             [+]Maintenance (child of Reports)                            Maintenance Report.txt(the ".txt" is only to show you this is the actual report)                   [+] Cost (child of Maintenance)             [+]Exspenses (child of Reports)                   [+] Job Cost (child of Exspenses)                            Exspenses Report.txt(the ".txt" is only to show you this is the actual report) ======================= end of example   ====================== In OnNM_ClickTreeCtrl() I cannot get the reports using this:      HTREEITEM hItem= m_cTree.GetSelectedItem();             HTREEITEM hChildItem = m_cTree.GetChildItem(hItem);             CString sSelText= m_cTree.GetItemText( hItem ); What is returns is whatever is selected including the button("[+]", the main heading, each child and finally the report.   How do I only receive the click on the Reports themselves, not all the headings? PLEASE use my example in your explaination, WITH(please) the appropriate code. Thanks in advance.

      A C++ programming language novice, but striving to learn

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      Larry Mills Sr wrote:

      In OnNM_ClickTreeCtrl()

      Its better to handle this in the selection changed event(TVN_SELCHANGED) other wise, if some one operate the tree control through keyboard, your application wont work.

      Larry Mills Sr wrote:

      How do I only receive the click on the Reports themselves, not all the headings?

      You can use the item data corresponding to each item, to identify whether the items is report or not. I mean, while inserting the report, you should set the item data(SetItemData) as some value, say X. When the selection change occurs, retrive the item data correspoding to that item, check whether the item data is X.

      nave [OpenedFileFinder] [My Blog]

      L 1 Reply Last reply
      0
      • N Naveen

        Larry Mills Sr wrote:

        In OnNM_ClickTreeCtrl()

        Its better to handle this in the selection changed event(TVN_SELCHANGED) other wise, if some one operate the tree control through keyboard, your application wont work.

        Larry Mills Sr wrote:

        How do I only receive the click on the Reports themselves, not all the headings?

        You can use the item data corresponding to each item, to identify whether the items is report or not. I mean, while inserting the report, you should set the item data(SetItemData) as some value, say X. When the selection change occurs, retrive the item data correspoding to that item, check whether the item data is X.

        nave [OpenedFileFinder] [My Blog]

        L Offline
        L Offline
        Larry Mills Sr
        wrote on last edited by
        #3

        Could you please provide a workable example for TVN_SELCHANGED?   Here's How I set up the TreeCtrl: strItems[0]= _T("Reports"); strItems[1]= _T("Construction"); strItems[2]= _T("Materials");      HTREEITEM hReportsItemRoot= m_cTree.InsertItem(strItems[0]);      HTREEITEM hConstItemRoot= m_cTree.InsertItem(strItems[1], hReportsItemRoot);      HTREEITEM hMaterialsItemRoot= m_cTree.InsertItem(strItems[2],hConstItemRoot); In your explaination, could you please use my example data, Please.

        A C++ programming language novice, but striving to learn

        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