急!!!请问怎样使数据集移动,但DBGRID控件显示不动?解决了给50分

chengzhongshi 2003-10-16 06:10:33
急!!!一个关于怎样使数据集移动,但DBGRID控件显示不动?解决了给50分
...全文
122 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhoutian618 2003-10-16
  • 打赏
  • 举报
回复
同意楼上几位的方法,
你试试看能不能解决你的问题,
我总感觉你的问题描述得还不是很清楚。

如果你的意思是说在运行某按钮的事件中不能移动数据的情况的话:
那么用以下的方法也是可以的。
这样连它的滚动条都不会动一下的。

DBGrid1.DataSource.DataSet:=nil;
try
//你的处理
fially
DBGrid1.DataSource.DataSet:=Query1;
end;
DongXF 2003-10-16
  • 打赏
  • 举报
回复
同意樓上
hiflower 2003-10-16
  • 打赏
  • 举报
回复
DBGrid.DataSource.DataSet.DisableControls;

DBGrid.DataSource.DataSet.EnableControls;
afei78223 2003-10-16
  • 打赏
  • 举报
回复
上面的While循环漏掉了do
While NOT EOF do
afei78223 2003-10-16
  • 打赏
  • 举报
回复

首先定义一个TScrollEvents类
type TScrollEvents = class
BeforeScroll_Event: TDataSetNotifyEvent;
AfterScroll_Event: TDataSetNotifyEvent;
AutoCalcFields_Property: Boolean;
end;

//此过程用来使DataSet的BeforeScroll 和AfterScroll 事件为空
procedure DisableDependencies(DataSet: TDataSet; var ScrollEvents: TScrollEvents);
begin
with DataSet do
begin
DisableControls;
ScrollEvents := TScrollEvents.Create();
with ScrollEvents do
begin
BeforeScroll_Event := BeforeScroll;
AfterScroll_Event := AfterScroll;
AutoCalcFields_Property := AutoCalcFields;
BeforeScroll := nil;
AfterScroll := nil;
AutoCalcFields := False;
end;
end;
end;

//此过程用来恢复DataSet的BeforeScroll 和AfterScroll 事件
procedure EnableDependencies(DataSet: TDataSet; ScrollEvents: TScrollEvents);
begin
with DataSet do
begin
EnableControls;
with ScrollEvents do
begin
BeforeScroll := BeforeScroll_Event;
AfterScroll := AfterScroll_Event;
AutoCalcFields := AutoCalcFields_Property;
end;
end;
end;

//使用的例子过程
procedure MoveDataSet(DataSet:TQuery);
var
ScrollEvents: TScrollEvents;
SavePlace: TBookmark;
begin
DisableDependencies(DBGrid.DataSource.DataSet, ScrollEvents);
SavePlace := DBGrid.DataSource.DataSet.GetBookmark;
with DataSet do
begin
While NOT EOF
Next;
end;
DBGrid.DataSource.DataSet.GotoBookmark(SavePlace); //到书签记录的地方
DBGrid.DataSource.DataSet.FreeBookmark(SavePlace);
EnableDependencies(DBGrid.DataSource.DataSet, ScrollEvents);
end;
e_shark 2003-10-16
  • 打赏
  • 举报
回复
dbgrid.datasource.dataset.dis...
dbgrid.datasource.dataset.enable...

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧