FMX.ListView.TListViewBase.OnDeleteItem

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

property OnDeleteItem: TDeleteItemEvent read FOnDeleteItem write FOnDeleteItem;

C++

__property TDeleteItemEvent OnDeleteItem = {read=FOnDeleteItem, write=FOnDeleteItem};

Properties

Type Visibility Source Unit Parent
event public
FMX.ListView.pas
FMX.ListView.hpp
FMX.ListView TListViewBase

Description

Occurs when a user requests the deletion of a list view item, after this deletion takes place. To catch the deletion before it takes place and be able to prevent it from actually happening, write an event handler for OnDeletingItem instead.

Event handlers for this event must expect the following parameters:

  • Sender, the list view.
  • AIndex, the index of the list view item that has been deleted.
    Note: You cannot access the data of the deleted item at this point, since a different item is now using that index in the list view. Write an event handler for OnDeletingItem instead if you need to access information about the deleted item.

The code snippet below updates the text in a status bar after an item is deleted to show the position of the deleted item, as well as the number of remaining items in the list:

Delphi:

procedure TMainForm.ListViewDeleteItem(Sender: TObject; AIndex: Integer);
begin
  StatusBar.Text := 'Item ' + IntToStr(AIndex+1) + ' has been removed from the list. ' +
                    IntToStr((Sender as TListView).Items.Count) + ' items remaining.';
end;

C++:

void __fastcall TMainForm::ListViewDeleteItem(TObject *Sender, int AIndex)
{
  TListView* list = reinterpret_cast<TListView*>(Sender);
  MainForm->StatusBar->Text = "Item " + UnicodeString(AIndex+1) + " has been removed from the list. " +
                              UnicodeString(list->Items->Count) + " items remaining.";
}

See Also