FMX.ListViewCheckList Sample

From RAD Studio Code Examples
Jump to: navigation, search

This is a project that shows how to make the display mode of a TListView behave as a check list, where you can tap items to add or remove them from the current selection.

Note: You can easily implement a check list in edit mode using one of the default TListView.ItemAppearance.ItemEditAppearance values.

Location

You can find the ListViewCheckList Sample sample project at:

  • Start | Programs | Embarcadero RAD Studio Sydney | Samples and navigate to:
    • Object Pascal\Multi-Device Samples\User Interface\ListView\ListViewCheckList
    • CPP\Multi-Device Samples\User Interface\ListView\ListViewCheckList
  • Subversion Repository:
    • You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.

Description

When you run the application, it shows a list view. Tapping an unselected item shows a checked check mark on its right-hand side. Tapping a selected item hides that check mark.

How to Use the Sample

  1. Navigate to the one of the locations given above, and open:
    • Delphi: ListViewCheckListProject.dproj
    • C++: ListViewCheckListProject.cbproj
  2. Press F9 or choose Run > Run.

Implementation

This application keeps a list of indexes of selected items.

The item appearance of this list view in display mode is the default value, ListItem, but this appearance has been modified. The properties of the TListView.ItemAppearance.Item.Accessory appearance object have been changed as follows:

To show or hide check marks as you tap list view items, this application handles the OnItemClick event of the list view. The handler of this event shows or hides the Accessory appearance object and updates the list of selected items that the application keeps.

This application also handles the OnUpdateObjects event of the list view, where it:

  • Adjusts the width of the Text appearance objects, so that text does not cover the check mark in the selected items.
  • Sets the visibility of the Accessory of each list view item based on the list of selected items. This is necessary because the rotation resets the list items to their default appearances.

Uses

See Also