[Overview][Constants][Types][Classes][Procedures and functions][Index] | Reference for unit 'ComCtrls' (#lcl)

# TCustomListView.Sort

Sorts the values in Items using the SortType, SortColumn, and SortDirection for the control.

## Declaration

Source position: comctrls.pp line 1628

`public procedure TCustomListView.Sort;`

## Description

Sort is a method used to reorder list items in the control using values in the SortType, SortColumn, and SortDirection properties. No actions are performed in the method when SortType is set to stNonem, or when SortColumn has a value which is not valid. SortColumn must be in the range 0..ColCount-1.

Sort uses a comparison routine in the implementation section to order the values in Items. The comparison routine is passed as argument to the Sort method in Items. The routine calls the OnCompare event handler (when assigned) to determine the order for list items. If OnCompare has not been assigned, it uses the Caption or SubItems (depending on SortColumn) to determine the new order for the list items. The value in SortDirection is handled when ordering the Items.

Sort saves and restores Focused or Selected items on exit. Checked items are also restored when OwnerData (or virtual mode) is not enabled.

Sort is called when a column header on the list view control is clicked and AutoSort is enabled.