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 !

有帮助吗?

解决方案

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;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top