删除并刷新您在DBgrid中保持相同位置的记录 [英] Delete and refresh a record in DBgrid where u maintain the same position

查看:109
本文介绍了删除并刷新您在DBgrid中保持相同位置的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小型数据库,正在使用dbgo,我有一个显示记录的DBgrid,我需要知道如何删除一条记录并刷新数据库,其中索引箭头保持相同的位置,或者至少转到下一个?但是目前,每次刷新时,我的索引箭头都会从头开始跳!

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 !

推荐答案

只需保留并重置Recno

Just keep and reset Recno

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

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

与DBNavigator一起使用的示例实现可能是

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;

这篇关于删除并刷新您在DBgrid中保持相同位置的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆