delphi中如何在不关闭和打开数据集的情况下刷新dbgrid?

发布于 2024-08-22 15:22:49 字数 113 浏览 11 评论 0原文

我需要不断地实时刷新 dbgrid。关闭和打开数据集工作正常,但会闪烁 dbgrid。我可以做什么来避免这种情况?

我想要一个像 Ajax 这样的解决方案,只更新必要的内容。

谢谢

I need to refresh dbgrid constantly, in real time. Close and open dataset works fine, but blink the dbgrid. What can I do to avoid this?

I'd like a solution like Ajax, that update only the necessary.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

作死小能手 2024-08-29 15:22:49

您是否尝试过使用Disable- &启用控件?

DataSet.DisableControls;
try
  DataSet.Close;
  DataSet.Open;
finally
  DataSet.EnableControls;
end;

此外,应该可以只调用 DataSet.Refresh 而不是关闭和打开来获得相同的结果。

Have you tried to use Disable- & EnableControls?

DataSet.DisableControls;
try
  DataSet.Close;
  DataSet.Open;
finally
  DataSet.EnableControls;
end;

Furthermore, it should be possible to just call DataSet.Refresh instead of closing and opening to get the same result.

心房的律动 2024-08-29 15:22:49

我在我的应用程序中使用它

DataSet.MergeChangeLog;
DataSet.ApplyUpdates(-1);
DataSet.Refresh;

上面的代码位于名为actRefreshDataaction中,在ActionManager

当我需要使用时我只需这样调用它

actRefreshData.Execute;

希望这有帮助。

提示:您可以添加一个计时器并自动执行此操作

I use this in my app

DataSet.MergeChangeLog;
DataSet.ApplyUpdates(-1);
DataSet.Refresh;

The above code is in an action named actRefreshData, in the ActionManager

When I need to use I just call it like

actRefreshData.Execute;

Hope this helps.

Hint: you can add a Timer and automate this

嗼ふ静 2024-08-29 15:22:49

看这里:

type THackDataSet=class(TDataSet); // a nice "hack" so we can access 
//protected members
 THackDBGrid=class(TDBGrid);

procedure {tdmdb.}refreshgrid(grid : tdbgrid);

var row, recno : integer;
    ds : tdataset;
    b : tbookmark;
begin
  Row := THackDBGrid(grid).Row;// or THackDataSet(ds).ActiveRecord

  ds := grid.datasource.dataset;

  RecNo := ds.RecNo;

  b := ds.GetBookmark;

  try
    ds.close;
    ds.Open;
  finally
    if (b<>nil) and ds.BookMarkValid(b) then
    try
     //      ds.GotoBookMark(b);
      ds.CheckBrowseMode;
      THackDataSet(ds).DoBeforeScroll;
      THackDataSet(ds).InternalGotoBookmark(b);
      if THackDataSet(ds).ActiveRecord <> Row - 1 then
      THackDataSet(ds).MoveBy(Row - THackDataSet(ds).ActiveRecord - 1);
      ds.Resync([rmExact{, rmCenter}]);
      THackDataSet(ds).DoAfterScroll;
    finally
      ds.FreeBookMark(b);
    end
    else if (recno<ds.RecordCount) and (recno<>ds.RecNo) then
    begin
      ds.First;
      ds.MoveBy(Max(0, recno-1));
    end;
  end;
end;

Look here:

type THackDataSet=class(TDataSet); // a nice "hack" so we can access 
//protected members
 THackDBGrid=class(TDBGrid);

procedure {tdmdb.}refreshgrid(grid : tdbgrid);

var row, recno : integer;
    ds : tdataset;
    b : tbookmark;
begin
  Row := THackDBGrid(grid).Row;// or THackDataSet(ds).ActiveRecord

  ds := grid.datasource.dataset;

  RecNo := ds.RecNo;

  b := ds.GetBookmark;

  try
    ds.close;
    ds.Open;
  finally
    if (b<>nil) and ds.BookMarkValid(b) then
    try
     //      ds.GotoBookMark(b);
      ds.CheckBrowseMode;
      THackDataSet(ds).DoBeforeScroll;
      THackDataSet(ds).InternalGotoBookmark(b);
      if THackDataSet(ds).ActiveRecord <> Row - 1 then
      THackDataSet(ds).MoveBy(Row - THackDataSet(ds).ActiveRecord - 1);
      ds.Resync([rmExact{, rmCenter}]);
      THackDataSet(ds).DoAfterScroll;
    finally
      ds.FreeBookMark(b);
    end
    else if (recno<ds.RecordCount) and (recno<>ds.RecNo) then
    begin
      ds.First;
      ds.MoveBy(Max(0, recno-1));
    end;
  end;
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文