Session 7

List View
(TListView, intra-program drag and drop)

Session #7

This session I demonstrate a very powerful UI component called a list view (TListView). The list view is one of the most powerful UI components, as it makes it easy to display lots of information very easily and makes the information easily accessible. It can even be made simple so computer beginners are not overwhelmed by the amount of data that is available. Everyone is familiar with the List View (even though most don't realize it), as it is the central component in Windows Explorer.

This is the form at design time:

The application at runtime:

Detailed viewList view

Small icons viewLarge icons view


The example is a modification of the previous List view example. I added a second TListView component. You can drag and drop between the two List Views, as well as drag and drop within a single list view.


This project demonstrates how to drag and drop between different windows (forms) of an application. In addition to the drag and drop stuff, I showed how to use the Anchor property of a component to properly resize a form.

The drag and drop demo shows how to copy items from one list box to another as well as move items from one list box to another. It also shows how to add items to a list box as well as insert into a particular position. The code for the two forms is trivial. The real work is done in the DragDropUtils.cpp support file.

The first formThe second form

Exercises

  1. In the first List View example, add the ability to sort on the file extension and path columns. (These are both strings.)
  2. Modify the first example so that the user can sort in both directions, ascending and descending. The first time the header is clicked, the data should be sorted in ascending order. The second click should sort in descending order. (Essentially, left-clicking toggles the sort order.)
  3. Add a popup menu to the list view that lets the user change some properties of the list view.
  4. "Fix" the UI so that, if the item is a folder (not a file), nothing is displayed in the size subitem. (It currently displays 0.)