Solved

Windows trees

Posted on 1998-08-04
1
233 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 100 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Suggested Courses

732 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