Dbgrid每页最多显示10条记录,按“→”键向下翻页,按“←”向上翻页。
解决方案 »
- 激活另一个进程的窗口
- 高手,急救 .有分
- 哪里有显示各种效果的源代码,例如浮雕,波浪
- 灵活查询有什么好的方法?
- 请问一下怎样把数据库配置窗口调出来,并能把配置信息读到程序中?
- 问个WebBrowser的另类问题
- 用 delphi 写数据库程序,使用什么做最简单,发布最方便?
- 怎么样让DBGRID只显示一条记录,要显示下一条记录,只能通过导航器按钮实现?
- Paradox7的数据表内容转入Interbase6.0中的表
- 用DELPHI 4.0创建SPLASH窗口的费解现象
- delphi利用XMLDocument实现对xml文件的增加、删除节点操作
- 在线请教:ScrollWindowEx 为啥总有几次不成功!?
2、
private
OldGridProc: TWndMethod;
procedure GridWindowProc(var Message: TMessage);
//...procedure TForm1.FormCreate(Sender: TObject);
begin
OldGridProc := DBGrid1.WindowProc;
DBGrid1.WindowProc := GridWindowProc;
end;procedure TForm1.GridWindowProc(var Message: TMessage);
var
Pos: SmallInt;
begin
OldGridProc(Message);
if Message.Msg = WM_VSCROLL then
begin
Pos := Message.WParam;
Table1.RecNo := Pos;
end;
end;
begin
if Key=#37 then
dbgrd1.Perform(WM_VSCROLL,SB_PAGEUP,0);
if Key=#39
dbgrd1.Perform(WM_VSCROLL,SB_PAGEDOWN,0);
end;
Query1.SQL.Text := 'select max(id) as maxid, min(id) as minid from TB1 ;
Query1.Open;
在点击ButtonNext按钮中,每点击一次计算一次最大bid
Query1.SQL.Text := 'select top 10 * from TB1 where id < bid order by id desc';
在点击ButtonPrev按钮中,每点击一次计算一次最小tid
'select * from (select top 10 * from TB1 where id > tid order by id asc) t order by id desc';DBGrid.DataSource.DataSet := Query1;procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=39 then
ButtonNext.Click;
if Key=37 then
ButtonPrev.Click;
end;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, DBTables, Grids, DBGrids;type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Table1: TTable;
procedure FormCreate(Sender: TObject);
procedure DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
OldGridProc: TWndMethod;
procedure GridWindowProc(var Message: TMessage);
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
begin
OldGridProc := DBGrid1.WindowProc;
DBGrid1.WindowProc := GridWindowProc;
end;procedure TForm1.GridWindowProc(var Message: TMessage);
var
Pos: SmallInt;
begin
OldGridProc(Message);
if Message.Msg = WM_VSCROLL then
begin
Pos := Message.WParam;
Table1.MoveBy(Pos*message.LParam);//這么做,是為了使得dataset指標跟著同步移動
end;
end;procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
VK_LEFT:
begin
SendMessage(DBGrid1.Handle,WM_VSCROLL, SB_PAGEUP,-1);
Key := 0;//琂礛オ龄璶癬page up and down狦碞ぃ琵膥尿矪瞶
end;
VK_Right:
begin
SendMessage(DBGrid1.Handle,WM_VSCROLL, SB_PAGEDOWN,1);
Key := 0;
end;
end;
end;end.
另外,“Dbgrid每页最多显示10条记录” ——是否可理解為12樓的分頁查詢呢?還是你的數據已經一次性取下來了,只是要翻頁而已?
var
HitEOF: Boolean;
begin
if InFetchData or AlreadyFetchAll then
Exit; InFetchData := True;
//鎖定UI,避免用戶誤操作
Form1.Enabled := False;
Screen.Cursor := crSQLWait;
try
cdsFetch.Close;
SQL := Format('SELECT TOP %d ITEM001, ITEM002 FROM WD2ITEM', [RecCountPerPage]); if (ParamValue = '') then
cdsFetch.CommandText := Format('%s WHERE %s>%s ORDER BY %s',
[SQL, PrimaryKeys, QuotedStr(LastPrimaryKeyValues), PrimaryKeys])
else
cdsFetch.CommandText := Format('%s WHERE %s>%s AND %s LIKE %s ORDER BY %s',
[SQL, PrimaryKeys, QuotedStr(LastPrimaryKeyValues), SearchField,
QuotedStr(Format('%%%s%%', [ParamValue])), PrimaryKeys]); Log(cdsFetch.CommandText);
cdsFetch.Open;
cdsFetch.Last;
LastPrimaryKeyValues := cdsFetch[PrimaryKeys];
//調用GridView的BeginUpdate,以避免更新紀錄時,造成其他事件被觸發
cxGrid1DBTableView1.BeginUpdate;
cdsData.AppendData(cdsFetch.Data, HitEOF);
AlreadyFetchAll := (cdsFetch.RecordCount < RecCountPerPage);
cxGrid1DBTableView1.Controller.FocusedRecordIndex := cxGrid1DBTableView1.Controller.TopRecordIndex;
cxGrid1DBTableView1.EndUpdate;
finally
cdsFetch.Close;
Screen.Cursor := crDefault;
InFetchData := False;
//解除UI鎖定
Form1.Enabled := True;
end; Log('### Fetch data ###');
end;