Enable Confirm delete in TDBAdvGrid

Hi,
Is there a way to show a delete confirmation dialog when the user presses Ctrl + Del to delete a row? (something similar to the ConfirmDelete of the DBGrid)

You can implement OnCanDeleteRow and from there show a confirmation dialog.

Thanks, I was trying to automatically assign to all tdbadvgrid that event and warn depending on whether a TCheckBox is checked or not.
I have created a component based on TDBAdvGrid with a CheckBox to be able to assign a different one to each TDBAdvGrid and thus control any deletion from a single procedure.

Not sure I fully understand what you mean. Would it be helpful to have this via a virtual method you can override in a descending component?

I use a Form as a template for the rest of the Forms in my project, I use it for the common elements (buttons, titles, etc.) and to assign event procedures to all the controls that I include in the forms that derive from it. I don't know if it is a good practice, I am updating and expanding an application made originally in Delphi 4.

In this case I want each DBAvdGrid to have a CheckBox and a DBNavigator associated, the CheckBox would serve to activate / deactivate the "Delete Registry?" Dialog, both for the DBAdvGrid and for the DBNavigator..

Through the component derived from TDBAdvGrid I relate the DBAdvGrid with its corresponding CheckBox and its DBNavigator. and in the Form template I assign to any DBAdvGrid in any Form derived from the template a CanDeleteRow event that uses the checkbox to show or not the confirmation message:

procedure TPlantillaFormDatosF.MiCanDeleteRow(Sender: TObject; ARow: Integer; var CanDelete: Boolean);
begin
if (Sender as TDBAdvGridAnsel).CheckConfirmarBorrado.Checked then
begin
if (CuadroMensaje('¿Borrar Registro?', mtConfirmation, [mbOK, mbCancel], mbCancel, 'Confirmar')=mrCancel) then
Abort;
end;
end;

Also, in the template, I assign a click event to the checkbox so that it modifies the ConfirmDelete of the DBNavigator.

I do not know if I have clarified the issue :slight_smile:

Regarding the virtual method, I do not know if it would be useful, the fact is that I have managed to solve it in a relatively easy way, I do not know if it would be useful for other cases.

I do not see in your code that you set the var parameter CanDelete to false when deleting is not permitted?

I know, I realized afterwards that surely Candelete aborted the deletion (I have tried it now and it is).

Is a component reference available with a description of all the methods and properties? The truth is, I don't know what many of the events and properties are for, and I don't have much time to experiment and see what they do.

TDBAdvGrid descends from TAdvStringGrid, so the TAdvStringGrid dev guide applies
http://www.tmssoftware.biz/download/manuals/TMS%20TAdvStringGrid%20Developers%20Guide.pdf

as well as the TDBAdvGrid specific dev guide:

1 Like