Delete a line in Dbgrid without deleting in Database

Asked

Viewed 688 times

2

Could erase one or more lines from a given Dbgrid without deleting the database record?

I was trying something like this but it didn’t work.

while not DataModuleGeral2.qryAudienciasInicial.Eof do
begin
  if (DM.qryAudienciasDATA_AUDIENCIA.AsDateTime = Date) and
     (DM.qryAudienciasHORA_AUDIENCIA.AsDateTime < Time) then
  begin
     frmTelaPrincipal.dbgAudiencias.SelectedRows.Delete;
  end else
    DataModuleGeral2.qryAudienciasInicial.Next;
end;

Utilise Firebird 2.5 and Delphi

  • 1

    It is not possible to delete a Dbgrid line that way. One idea would be to throw the dice into a Stringgrid and manipulate through it.

  • 1

    Have you thought about putting everything on a Clientdataset?

  • might be a good idea...

2 answers

3

You can use the qryAuditionsInitial Filter field to hide records you don’t want to show the user

Something like

qryAudienciasInicial.Filter:='(ID<>5) AND (ID<>6)';
qryAudienciasInicial.Filtered:=true;

Of course here you should save the logs that the user is deleting to make this filter more dynamic.

2

You can throw the data into a Tfdmemtable instead of working directly on the query, then you link the Tfdmemtable in Dbgrid. To delete the records you want just remove them from the Tfdmemtable and after a refresh on the grid.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.