1. Technology

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.

Implementing MaxLength For Delphi's TListView Edit Control
The ReadOnly property of a List View, determines whether the user can change the contents of the control - caption of an item. Since using TEdit we (Delphi developers) are used to have the MaxLength property. Here's how to limit the number of characters a user can enter into the ListView's editor control.

Implementing OnStateIconClick In TListView
Each item in a list view can have an icon next to it. The list of icons is defined by the SmallImages (and/or LargeImages) property. Further, the StateImages property defines additional images to display next to each item in the list view. Use StateImages to implement radio group like list view - where only one item can be checked.

Group Items in a Delphi's TListView Control
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.

Rearrange Multiple TListView Items using Drag and Drop
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.

Force TListView's Edit Mode using a Keyboard Shortcut
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.

Implementing On Item Click / Double Click for TListView
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.

Implementing the On Item Checked Event for the TListView Control
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.

Implement Custom Sorting for a TListView component
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

Use Custom Check Box Images for a ListView
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.

Display Custom Hints for TListView Sub Items
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.

Placing a TProgressBar into a TListView
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!

Custom Drawing of TListView Items - Font, Colors, Graphics
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.

©2014 About.com. All rights reserved.