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

# TListItems.Exchange

Exchanges the positions for the specified list items in the container.

## Declaration

Source position: comctrls.pp line 1174

`public procedure TListItems.Exchange(`
`const AIndex1: Integer;`
`const AIndex2: Integer`
`);`

## Arguments

`AIndex1` |  | Ordinal position for a list item moved in the method.
`AIndex2` |  | Ordinal position for a list item moved in the method.

## Description

Exchange is a method used to swap the positions for the list items specified in the AIndex1 and AIndex2 arguments. No actions are performed in the method when AIndex1 and AIndex2 have the same values.

An Exception is raised if AIndex1 or AIndex2 contain a value that is not a valid ordinal position in the container. (&lt 1 or &gt Count-1).

Values in the Selected and ItemFocused properties for the list view control are saved prior to swapping the list items. These properties are restored prior to exiting from the method. Flags in the list view control are updated to include lffItemsMoving when the operation is started. The flag value is removed when the operation is completed.

Exchange calls the TFPList.Exchange method to change the positions for the specified list items in the internal storage for the container. The list item in AIndex1 becomes the active cache item after the values have been swapped. The widgetset class for the list view control is notified of the change when its handle is allocated.

Use Move to relocate a list item to a specific ordinal position in the container.

Use InsertItem to insert a list item at a specific position in the container.

## Errors

Raises an Exception with the message in rsListIndexExceedsBounds if AIndex1 or AIndex2 contain a value that is not a valid ordinal position in the container.

## See also

TListItems.Move |  | Moves the list item at the specified position to a new position in the container.
TListItems.InsertItem |  | Inserts the specified list item at the specified position in the internal storage for the container.
TCustomListView.Selected |  | Contains the selected list item in the list view control.
TCustomListView.ItemFocused |  | The list item which has focus on the control.
TListViewFlag |  | Represents flag values used in TCustomListView when sorting or validating items in the control.
TListViewFlags |  | Set type used to store values from the TListViewFlag enumeration.