Pregunta

I have a small database I'm using dbgo, I have a DBgrid displaying my records, I need to know how to delete a record and refresh the database where the index arrow stays in the same position or at least go to the next? but currently my index arrow jump to start form the beginning each time I refresh !

¿Fue útil?

Solución

Just keep and reset Recno

var
I:Integer;
.......

I := Ads.Recno;
Ads.Delete;
Ads.Recno := I;

an example implementation for usage with DBNavigator could be

Procedure DeleteAndKeepRecno(Ads: TCustomAdoDataset);
var
  rn: Integer;
begin
  rn := Ads.RecNo;
  Ads.Delete;
  Ads.RecNo := rn;
end;

procedure TForm4.DBNavigator1Click(Sender: TObject; Button: TNavigateBtn);
begin
  if Button = nbDelete then
  begin
    DeleteAndKeepRecno (TCustomAdoDataset(TDBNavigator(Sender).DataSource.DataSet));
    Abort;
  end;
end;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top