FMX.ListView.TListViewBase.OnDeletingItem

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

property OnDeletingItem: TDeletingItemEvent read FOnDeletingItem write FOnDeletingItem;

C++

__property TDeletingItemEvent OnDeletingItem = {read=FOnDeletingItem, write=FOnDeletingItem};

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, before this deletion takes place. You can define an event handler for this event to prevent the deletion from actually happening based on your own criteria.

Event handlers for this event must expect the following parameters:

  • Sender, the list view.
  • AIndex, the index of the list view item to be deleted.
  • ACanDelete, variable that determines whether the list view item is to be deleted or not.

To prevent the deletion from happening, set ACanDelete to False in your event handler.

The code snippet below shows a dialog box asking for confirmation before deleting an item. If you click Cancel, ACanDelete is set to False, canceling the list view item deletion:

Delphi:

procedure TMainForm.ListViewDeletingItem(Sender: TObject; AIndex: Integer; var ACanDelete: Boolean);
var
  Input: Integer;
begin
  Input := TDialogServiceSync.MessageDialog(
    'Are you sure that you want to remove "' +
        (Sender as TListView).Items[AIndex].Text + '" from the list?',
    TMsgDlgType.mtConfirmation, mbOKCancel, TMsgDlgBtn.mbOK, 0);
  if Input = 2 then // Cancel
    ACanDelete := False;
end;

C++:

void __fastcall TMainForm::ListViewDeletingItem(TObject *Sender, int AIndex, bool &ACanDelete)
{
  TListView* list = reinterpret_cast<TListView*>(Sender);
  int input = TDialogServiceSync::MessageDialog(
      "Are you sure that you want to remove \"" +
          list->Items->Item[AIndex]->Text + "\" from the list?",
      TMsgDlgType::mtConfirmation, mbOKCancel, TMsgDlgBtn::mbOK, 0);
  if (input == 2) { // Cancel
        ACanDelete = false;
  }
}

See Also