Session 8

Tree View
(TTreeView, TTreeNode, ShellExecute, drag and drop, traversing the Windows file system recursively)

Session #8

During this session, I showed how to use another very powerful component, the TTreeView. This is the primary component used in Windows Explorer. It's used whenever you want to represent a hierarchy or parent-child relationship. There's not a lot on this page, but there is a ton of stuff going on in the project that you can see by downloading the code.

  • MainForm.h - The definition of the main form.
  • MainForm.cpp - The implementation.
  • Project .zip file - Project files to build it yourself.

    Although you can't tell by looking at the screenshot, you can drag and drop files/folders from Windows Explorer. That's the real power in this example project.

    There are several 3rd-party add-on tree view controls out there. One of the best (and possibly the best) is Virtual Treeview. It is free, comes with source (Delphi) and has been used in countless real-world applications. It has a steep learning curve, but, if you're serious about UI design and need a tree view component, check it out. There are other freeware and commercial tree view components as well.

Exercises

  1. Currently, the TTimer object is always enabled and updating the counts several times each second. Modify it so that the timer is only active while the files/folders are being searched. In other words, it is de-activated after the search completes.