Chapter 14. TreeView and ListView

The world is very confusing, with information everywhere—some related, some not. To survive, Homo sapiens have learned to organize: it is a survival trait. Two primary organization tools in .NET applications are lists and tree controls.

The essential character of a list is that it is linear, without branches or levels. The list can contain all the objects in a group or a subset, filtered according to an appropriate algorithm. It can be sorted: alphabetically, or by cost, color, or any number of other parameters, or not at all.

An alternative, and complementary, way to organize and classify is hierarchically. A hierarchical organization is comprised of parent/child relationships. Each object is at a specific level in the hierarchy, and each object can have a parent object, a child object, neither, or both. The best way to represent hierarchical organizations is with a tree structure, often drawn upside down, as shown in Figure 14-1.

Tree structure

Figure 14-1. Tree structure

The stereotypical, and most visible, use of list and tree controls in the Windows world is Windows Explorer, the file and directory management program that has been included with Windows since Windows 95. Files and directories (folders in the new parlance) lend themselves well to this blend of hierarchical and ListViews. Explorer uses a tree view control on the left to show the hierarchical nature ...

Get Programming .NET Windows Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.