我需要实时刷新dbgrid。关闭和打开数据集工作正常,但闪烁dbgrid。我该怎么做才能避免这种情况?
我想要像Ajax这样的解决方案,只更新必要的。
由于
答案 0 :(得分:14)
您是否尝试使用禁用 - & EnableControls 强>
DataSet.DisableControls;
try
DataSet.Close;
DataSet.Open;
finally
DataSet.EnableControls;
end;
此外,应该可以只调用DataSet.Refresh而不是关闭和打开以获得相同的结果。
答案 1 :(得分:0)
我在我的应用中使用它
DataSet.MergeChangeLog;
DataSet.ApplyUpdates(-1);
DataSet.Refresh;
以上代码位于action
ActionManager
中
当我需要使用时,我只需将其称为
actRefreshData.Execute;
希望这有帮助。
提示:您可以添加Timer
并自动执行此操作
答案 2 :(得分: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;