Delete and refresh a record in DBgrid where u maintain the same position

喜欢而已 提交于 2019-12-25 05:25:33

问题


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:


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;


来源:https://stackoverflow.com/questions/15600289/delete-and-refresh-a-record-in-dbgrid-where-u-maintain-the-same-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!