Show: Delphi C++
Display Preferences

FMX.ListView.TListView.OnDeletingItem

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

property OnDeletingItem: TListViewBase.TDeletingItemEvent read FOnDeletingItem write FOnDeletingItem;

C++

__property OnDeletingItem;

Properties

Type Visibility Source Unit Parent
event published
FMX.ListView.pas
FMX.ListView.hpp
FMX.ListView TListView

Description

Occurs when a user requests the deletion of a list view item, before this deletion takes place.

FMX.ListView.TListView.OnDeletingItem inherits from FMX.ListView.TListViewBase.OnDeletingItem. All content below this line refers to FMX.ListView.TListViewBase.OnDeletingItem.

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

Personal tools
In Other Languages
Previous Versions
Assistance