Click here to Skip to main content
15,886,714 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using a CTreeCtrl for managing the directory and folders. But it only shows the folders, not the files inside.

Now i want to fill the CListCtrl with all the files in the subfolders and folders when selecting tree item.

This is my CTreeCtrl code:

C++
BOOL DirTreeCtrl::OnItemexpandedTree1(NMHDR *pNMHDR, LRESULT *pResult)
{
    LPNMTREEVIEW pNMTreeView = reinterpret_cast<lpnmtreeview>(pNMHDR);
    // TODO: Add your control notification handler code here
    HTREEITEM hItem = GetFirstVisibleItem();
    *pResult = 0;
    while (hItem)
    {
        if (GetItemState(hItem, TVIS_EXPANDED) & TVIS_EXPANDED)
            SetItemImage(hItem, 2, 2);
        else SetItemImage(hItem, 0, 0);
        if (GetItemText(hItem) == "..")
        {
            HTREEITEM parItem = GetParentItem(hItem);
            DeleteItem(hItem);
            SetItemImage(parItem, 2, 2);
            
            CString temp;
            char curPath[_MAX_PATH];
            
            getcwd(curPath, _MAX_PATH);
            chdir(m_drive + ":");
            RecurDirs(ConstructPath(parItem), parItem);
            chdir(curPath);
            
            return FALSE;
        }
        hItem = GetNextVisibleItem(hItem);
    }
    
    *pResult = 0;
    
    return FALSE;
    *pResult = 0;
}


Please help
Posted
Updated 3-Sep-14 22:03pm
v2
Comments
Richard MacCutchan 4-Sep-14 4:04am    
Exactly what help are you asking for?
BiggiSmalls 4-Sep-14 6:44am    
When i click on tree item (folder) i want to show all files in that folder and subfolder to a list control. I need a explanation of the code what to do when i click ONSELELECTION_CHANGED_TREE.
Richard MacCutchan 4-Sep-14 6:57am    
You need to create a ListControl, then extract all the files and directories below the selected path and add them to your ListControl. You probably need to include some extra information in each item to distinguish between files and directories. You can then sort the control with your own callback routine before displaying the results. See http://msdn.microsoft.com/en-us/library/hfshke78.aspx for more information.
BiggiSmalls 4-Sep-14 7:02am    
Yes i already created the ListControl, when i select an item from the TreeControl, it saves the path of the folder in a edit control box. Now i need like you said from this selected path to show all the files in the ListControl, but i totaly lost right now, can you help me little bit more with this?
Richard MacCutchan 4-Sep-14 7:09am    
You use FindFirstFileEx and its associated functions to get all the filenames from the directory.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900