0
votes

I created a simple MFC application that is Dialog based. I dragged a TreeControl onto the dialog resource editor. I gave it a member variable name. I also have a button with an event handler function. When I click the button, I want to populate the tree.

The problem is, only the root element is being added, nothing else. Any ideas?

`

void CCrysisDialogDecryptorDlg::OnBnClickedButton1()
{
    HTREEITEM hItem, hCar;
    hItem = m_directoryListing.InsertItem(L"C:\\",TVI_ROOT);
    hCar = m_directoryListing.InsertItem(L"Child",hItem);
    m_directoryListing.InsertItem(L"Grandchild",hCar);
    m_directoryListing.InsertItem(L"Grandchild",hCar);
    m_directoryListing.InsertItem(L"Grandchild",hCar);
}

`

1

1 Answers

1
votes

There is nothing wrong in your code, I tried same code and it worked. There might be possibility you see only a root element as tree is not by default expanded. You can add below code to expand your tree and try if you see all elements.

    hItem= m_directoryListing.GetFirstVisibleItem();
    while (hItem != NULL)
    {
        m_directoryListing.Expand(hItem,TVE_EXPAND);
        hItem= m_directoryListing.GetNextItem(hItem, TVGN_NEXTVISIBLE);
    }