I'm sorry, That puts the list in cokums. I do not want that type.
Main Topics
Browse All TopicsI've never used a "Tree Control" I need a solid example of how to use it:
the following BOOLs are set:
m_bHasButtons = TRUE;// button style
m_bHasLines = TRUE;//has lines
m_bLinesAtRoot = TRUE;//root lines
m_bShowSelAlways = TRUE;//always show
m_bSingleExpand = TRUE;//allow single expand only
In the program I want to list files(database reports) for each Heading;
Ex: Headings, Shop, Yard, Building, Motorpool, Maintenance, Construction.
Question 1) How do I show these Headings in the TreeCtrl(named: CTreeCtrl m_cTree) and Question 2) Then be able to insert various "Reports" for each heading(different amount of reports for each heading?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
See the Article:
How to Accept Drag-and-Drop Files from Windows Explorer
http://www.experts
...whic
To create the tree, I just right-clicked it in the Dialog Editor and selected Add Variable (m_ctrlTree)
To populate the tree shwon in the example, I used code like the attached:
HTREEITEM hItemRoot= m_ctlTree.InsertItem("All Tasks");
HTREEITEM hItemTBD= m_ctlTree.InsertItem("To Be Done", hItemRoot);
HTREEITEM hItemDone= m_ctlTree.InsertItem("Done
In your example, is "hItemTBD" a subItem of " hItemRoot"?, is "hItemDone" a subitem of "hItemTBD" or " hItemRoot"? What would I use to insert a Report name under "hItemDone" let's say the report name is "Construction Report" how would I insert that report name under "hItemDone" ?
Also, is the code for finding out what was selected the same as the Combobox or List Control?
Example:
CString m_csCategory = "";
int m_nDropListIndex = 0;
POSITION p = m_cCat_Tree.GetFirstSelect
//m_nDropListIndex = m_cCat_Tree.GetNextSelecte
m_nDropListIndex = m_cCat_Tree.GetCurSel();
if( m_nDropListIndex < 0 )
{
return;
}
m_cCat_Tree.GetLBText( m_nDropListIndex, m_csCategory );
Did yo look a the Article? There is an image that shows the hierarchy.
>> ... a Report name under "hItemDone" let's say the report name is "Construction Report" how would I insert that report name under "hItemDone" ?
Exactly as shown, only use your own text:
m_ctlTree.InsertItem( "Construction Report", hItemDone );
>> finding out what was selected
Use the GetSelectedItem function:
CTreeCtrl::GetSelectedItem
http://msdn.microsoft.com/
================
I think it will help you a lot to take a few minutes to read the MFC documentation about tree controls. I sort of assumed that you had already done that.
Using CTreeCtrl
http://msdn.microsoft.com/
CTreeCtrl Members
http://msdn.microsoft.com/
I looked at the MSDN stuff and got more confused as I read mon. That's why I choose to ask Experts Exchange! I saw the CTreeCtrl::GetSelectedItem
Reports (main Heading
Construction (Heading)
Materials
Cost
Construction Exspenses.txt // actual report
Maintenance (Heading)
vheicle repairs
TruckRepairs.txt// actual report
Parts Cost
Vehicle Exspenses Report.txt
Now, please use the example you presented and show me How I would detect which ".txt" report was clicked on, PLEASE!
Whichever item is highlighted is the "selected item." So if the user clicked on
Construction Exspenses.txt
then that item would be selected -- it would be displayed in a black selection rectangle.
If you then called GetSelectedItem() you would get an HTREEITEM. Given that, you can find out what its text is. For example:
HTREEITEM hItem= m_ctrlTree.GetSelectedItem
CString sSelText= m_ctrlTree.GetItemText( hItem );
MessageBox( sSelText ); // display the text of the selected tree node
Dan,
This code:
HTREEITEM hItem= m_ctrlTree.GetSelectedItem
CString sSelText= m_ctrlTree.GetItemText( hItem );
MessageBox( sSelText ); // display the text of the selected tree node
works okay except any selection you select (including the Tree "Buttons" and the Headings) are returned How do I get only the subitems (the actual reports) instead of the Headings and buttons?
Usually, part of a tree is structure (branches) and the key info is in the "leaves"
The normal way to tell one from the other is this: When you populate the tree, you assign a special value into the "item data" (SetItemData). Then whenever you need to know about the clicked or otherwise selected iem, you check the item data (GetItemData) to see if you need to take action.
As to the rest... it is your program that populates the tree, right? So when you insert a new node, you know the full path and directory of the report, even though you only display the filename. You just need to programmatically "remember" whatever you will need to know later. This is usually done with an in-memory array, a database recordset, or any of a number of other standard programming techniques.
My Code:
strItems[0]= _T("Reports");
strItems[1]= _T("Construction");
strItems[2]= _T("Materials");
HTREEITEM hReportsItemRoot= m_cTree.InsertItem(strItem
HTREEITEM hConstItemRoot= m_cTree.InsertItem(strItem
HTREEITEM hMaterialsItemRoot= m_cTree.InsertItem(strItem
There's more, but you can see my strategy above. At what point do I use this "When you populate the tree, you assign a special value into the "item data" (SetItemData). ":
(I thought SetItemData was used to populate the control itself.)
Please be patient with me and show me how to do this, also do I use a series of If ... else if .. else statement to compare the return in NM+Click or SelChanged ? an example would be nice
Business Accounts
Answer for Membership
by: IbanUlovPosted on 2009-10-25 at 15:17:54ID: 25658694
Here you have a complete good example: /KB/tree/C ColumnTree Ctrl.aspx
http://www.codeproject.com