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