7

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

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

谢谢

4

3 回答 3

14

您是否尝试过使用Disable- & EnableControls

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

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

于 2010-02-22T13:19:10.390 回答
0

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

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

上面的代码在一个action名为actRefreshData中,在ActionManager

当我需要使用时,我只是将其称为

actRefreshData.Execute;

希望这可以帮助。

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

于 2016-11-05T21:30:09.693 回答
0

看这里:

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;
于 2017-08-22T13:23:01.510 回答