?
Solved

Windows trees

Posted on 1998-08-04
1
Medium Priority
?
236 Views
Last Modified: 2013-11-19
Dear experts,
How do you get the tree function to behave like a normal windows tree function..
When you use this code the icons show as an open folder only when you select them and they dont stay open as you continue down the tree?
I want this tree to behave as a normal windows explorer tree.. that is the icons will show as folder open as you traverse down the tree and will close as you come back up the tree.
(Also for the images
image 0 = folder closed
image 1 = floder closed
image 2 = folder open)

The current code..(this is for use in a dialog box)


    // Create the Image List.
      m_treeImageList.Create(13, 13, FALSE, 3, 0);
      HICON hIcon = ::LoadIcon(AfxGetResourceHandle(),
            MAKEINTRESOURCE(IDI_ICON1));//CHANGE your Icons here
      m_treeImageList.Add(hIcon);
      hIcon = ::LoadIcon(AfxGetResourceHandle(),
            MAKEINTRESOURCE(IDI_ICON1));//CHANGE your Icons here
      m_treeImageList.Add(hIcon);
      hIcon = ::LoadIcon(AfxGetResourceHandle(),
            MAKEINTRESOURCE(IDI_ICON2));//CHANGE your Icons here
      m_treeImageList.Add(hIcon);

    m_treeView.SetImageList(&m_treeImageList, TVSIL_NORMAL);//this is optional

      // Create the root item.
      TV_ITEM tvItem;
      tvItem.mask =
            TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
      tvItem.pszText = "Root";
      tvItem.cchTextMax = 4;
      tvItem.iImage = 1;
      tvItem.iSelectedImage = 2;
      TV_INSERTSTRUCT tvInsert;
      tvInsert.hParent = TVI_ROOT;
      tvInsert.hInsertAfter = TVI_FIRST;
      tvInsert.item = tvItem;
      HTREEITEM hRoot = m_treeView.InsertItem(&tvInsert);

      // Create the first child item.
      tvItem.pszText = "Child Item 1";
      tvItem.cchTextMax = 12;
      tvItem.iImage = 1;
      tvItem.iSelectedImage = 2;
      tvInsert.hParent = hRoot;
      tvInsert.hInsertAfter = TVI_FIRST;
      tvInsert.item = tvItem;
      HTREEITEM hChildItem = m_treeView.InsertItem(&tvInsert);

      // Create a child of the first child item.
      tvItem.pszText = "Child Item 2";
      tvItem.cchTextMax = 12;
      tvItem.iImage = 1;
      tvItem.iSelectedImage = 2;
      tvInsert.hParent = hChildItem;
      tvInsert.hInsertAfter = TVI_FIRST;
      tvInsert.item = tvItem;
      m_treeView.InsertItem(&tvInsert);

      // Create another child of the root item.
      tvItem.pszText = "Child Item 3";
      tvItem.cchTextMax = 12;
      tvItem.iImage = 1;
      tvItem.iSelectedImage = 2;
      tvInsert.hParent = hRoot;
      tvInsert.hInsertAfter = TVI_LAST;
      tvInsert.item = tvItem;
      m_treeView.InsertItem(&tvInsert);
0
Comment
Question by:Soth
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
Andy_Keys earned 200 total points
ID: 1320271
Look at changing the icon when you get an Exanding or expanded messaage. ie when you get the expandeding use (TVE_EXPAND == pNMTreeView->action) to see if its expanding or collasping and change the icon accordinlg
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question