Delete and refresh a record in DBgrid where u main

2019-09-14 21:51发布

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 !

1条回答
倾城 Initia
2楼-- · 2019-09-14 22:21

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;
查看更多
登录 后发表回答