TListView - Delphi Usage Examples, Tips and Tricks
The TListView Delphi control displays a list of items in a fashion similar to how Windows Explorer displays files and folders. Items can be displayed in columns with column headers and sub-items, or vertically or horizontally, with small or large icons. Learn how to use the list view control in Delphi programs.
The TListView Delphi control displays and manages a list of items, displayed in columns, vertically or horizontally, with small or large icons. If you are using Delphi 2007, Delphi 7 or any other previous version, you can also have grouping (with expand, collapse) functionality in the TListView control. Here's one implementation idea.
Using Delphi's drag and drop operations it is easy to implement rearranging multiple items in a TListView control. Most MP3 (any multimedia) players allow arranging playlist using the technique provided below.
At run time, when ReadOnly is FALSE, the user can click the selected item to "enter" the edit mode. Upon entering the edit mode, the in-place editor for the item’s caption is placed "above" the selected item.
Unfortunatelly, if you need to know what list view item was clicked or double clicked you cannot simply handle the OnClick / OnDblClick events to get the clicked item. You need to call the GetHitTestInfoAt function and make sure the click event occured over an actual item. Here's how.
When the ViewStyle property is set to vsReport and CheckBoxes is set to true, ListView includes a check box next to the items in the list. If you need to react when the checked state of an item changes you need to tweek the message handling processing of the TListView control.
Suppose you have assigned numbers for the TListItem Caption property and need to sort the ListView when displayed in a report-style. To use custom sorting handle the OnCompare event. If an OnCompare event handler is assigned, AlphaSort method uses that event handler to define the sort order - call AlphaSort to sort the items
When the ViewStyle property of a TListView Delphi control is set to vsReport and CheckBoxes is set to true, list view includes a check box next to the items in the list. By design this check box is, well, "ugly". It has a nasty thick 2 pixel border - and there's no property to change it.
To force a list view to display custom hints for items and sub items, you need to handle two events: OnInfoTip and OnMouseMove. Here's the implementation of the OnInfoTip event handler.
Here's how to add a progress bar (or any other Delphi component) to a ListView control. Plus: full source code to the TListViewEx component (TListView descendant) with ColumnResize events!
If you want to apply custom drawing (fonts, color, graphics) for each individual list item you can simply handle an event or two - and have a list view full of color and visually more attractive elements.