ListView

The ListView control displays a list of items, with optional icons and subitems associated with each. A ListView is used as the right pane in Windows Explorer, displaying the files and directories contained within the directory currently selected in the tree view in the left pane. The ListView class contains a number of useful properties, methods, and events, listed in Tables Table 14-17, Table 14-22, and Table 14-23, respectively.

The ListView control contains a collection of objects of type ListViewItem: the Items property (listed in Table 14-17, along with other commonly used ListView properties). The Items property itself is of type ListViewItemCollection, which has methods (listed in Table 14-30) for adding, inserting, removing, and otherwise manipulating items in the collection.

The ListViewItemCollection class implements the ICollection interface, the IList interface that derives from it, and the IEnumerable interface. The first two interfaces provide access to individual items via a zero-based index, and the IEnumerable interface provides the capability to iterate over the collection. Both features are central to the capabilities of the ListView, as seen below.

The ListView control can be viewed in one of four ways, specified by the ListView.View property: large icon, small icon, list, and detail. Valid values of the View property, corresponding to each of these view modes, are members of the View enumeration, listed and described in Table 14-21.

When the View property ...

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.