線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1547
推到 Plurk!
推到 Facebook!

tdbgrid可以做分頁顯示嘛?

尚未結案
donlly
一般會員


發表:45
回覆:73
積分:23
註冊:2004-11-30

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-12-15 12:57:12 IP:219.131.xxx.xxx 未訂閱
有時候tdbgrid要顯示太多資料的時候,有什么方法可以分頁顯示? 例如,有3000條資料,我想把它分成3頁顯示,每頁1000條,當click第2頁(button)的時候,顯示1001到2000的,click第3頁的時候,顯示2001到3000的 怎樣實現這功能呢?謝謝
deity
尊榮會員


發表:90
回覆:876
積分:678
註冊:2003-05-09

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-12-15 14:12:26 IP:218.15.xxx.xxx 未訂閱
donlly您好: 试试下面的做法,看看对您有无帮助: 問題】delphi 数据库如何 分页显示? http://delphi.ktop.com.tw/topic.php?topic_id=40375 問題】限制筆數 http://delphi.ktop.com.tw/topic.php?topic_id=43190 如何使Dbgrid的記錄分頁顯示? http://delphi.ktop.com.tw/topic.php?topic_id=36368 問題】太大量記錄,想分批讀入Grid中 http://delphi.ktop.com.tw/topic.php?topic_id=58906 問題】分頁讀取資料 http://delphi.ktop.com.tw/topic.php?topic_id=46335 ——行径窄处,留一步与人行—— 發表人 - deity 於 2004/12/15 14:23:07
donlly
一般會員


發表:45
回覆:73
積分:23
註冊:2004-11-30

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-12-16 10:29:24 IP:219.131.xxx.xxx 未訂閱
//首先設定PageSize,取出PageCount
procedure TForm1.Button1Click(Sender: TObject);
begin
  ADoquery1.Recordset.PageSize :=spinedit1.Value;
  Edit1.Text := IntToStr(ADoquery1.Recordset.PageCount);
  ShowData(spinedit2.Value);
end; 
 
procedure TForm1.ShowData(page:integer);
var
  iRow, iCol, iCount : Integer;
  rs : ADOInt.Recordset;
begin
  ADoquery1.Recordset.AbsolutePage:=Page;
  Currpage:=page;        iRow := 0;
  iCol := 1;
  stringgrid1.Cells[iCol, iRow] := 'FixedCol1';
  Inc(iCol);
  stringgrid1.Cells[iCol, iRow] := 'FixedCol2';
  Inc(iRow);
  Dec(iCol);      rs := adoquery1.Recordset;
  for iCount := 1 to SpinEdit1.Value do 
  begin
    stringgrid1.Cells[iCol, iRow] := rs.Fields.Get_Item('FieldName1').Value;
    Inc(iCol);
    stringgrid1.Cells[iCol, iRow] := rs.Fields.Get_Item('FieldName1').Value;
    Inc(iRow);
    Dec(iCol);
    rs.MoveNext;
  end;
   
//上一頁 
procedure TForm1.Button2Click(Sender: TObject);
begin
  If (CurrPage)<>1 then
   ShowData(CurrPage-1);
end;    //下一頁
procedure TForm1.Button3Click(Sender: TObject);
begin
  If CurrPage<>ADoquery1.Recordset.PageCount then
    ShowData(CurrPage 1);
end;
以上程式碼是把StringGrid的資料分頁顯示,但是執行的時候有問題, 當click上一頁 或下一頁的時候沒有反應,各位可以指點一下嘛?謝謝 發表人 - donlly 於 2004/12/16 10:31:25
deity
尊榮會員


發表:90
回覆:876
積分:678
註冊:2003-05-09

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-12-16 15:19:48 IP:218.15.xxx.xxx 未訂閱
引言: //首先設定PageSize,取出PageCount
procedure TForm1.Button1Click(Sender: TObject);
begin
  StringGrid1.RowCount:=spinedit1.Value 1;//确保够空间显示出记录数来
  ADoquery1.Recordset.PageSize :=spinedit1.Value;//指定每页显示的记录数
  Edit1.Text := IntToStr(ADoquery1.Recordset.PageCount);//获得总页数
  ShowData(spinedit2.Value);//获得当前所查看页的内容,也即spinedit所对应页的记录
end; 
 
procedure TForm1.ShowData(page:integer);
var
  iRow, iCol, iCount : Integer;
  rs : ADOInt.Recordset;
begin
  ADoquery1.Recordset.AbsolutePage:=Page;
  Currpage:=page;        iRow := 0;
  iCol := 1;
  stringgrid1.Cells[iCol, iRow] := 'FixedCol1';//设置stringgrid的标题
  Inc(iCol);
  stringgrid1.Cells[iCol, iRow] := 'FixedCol2';
  Inc(iRow);
  Dec(iCol);      rs := adoquery1.Recordset;
  for iCount := 1 to SpinEdit1.Value do 
  begin
    stringgrid1.Cells[iCol, iRow] := rs.Fields.Get_Item('FieldName1').Value;//对应数据源的字段值,FieldName1为AdoQuery1存在的字段名
    Inc(iCol);
    stringgrid1.Cells[iCol, iRow] := rs.Fields.Get_Item('FieldName1').Value;
    Inc(iRow);
    Dec(iCol);
    rs.MoveNext;
  end;
   
//上一頁 
procedure TForm1.Button2Click(Sender: TObject);
begin
  If (CurrPage)<>1 then
   ShowData(CurrPage-1);
end;    //下一頁
procedure TForm1.Button3Click(Sender: TObject);
begin
  If CurrPage<>ADoquery1.Recordset.PageCount then
    ShowData(CurrPage 1);
end;
以上程式碼是把StringGrid的資料分頁顯示,但是執行的時候有問題, 當click上一頁 或下一頁的時候沒有反應,各位可以指點一下嘛?謝謝 發表人 - donlly 於 2004/12/16 10:31:25 得注意几点: 1、确定有没有 uses ADOInt; 2、确定AdoQuery1数据源有没有数据,有没有open,即设Adoquery1.active:=true; 3、var Form1: TForm1; Currpage:integer;//定义Currpage这个全局变量 implementation uses ADOInt; {$R *.dfm} 我试了是可以的,您试试看
——行径窄处,留一步与人行——
donlly
一般會員


發表:45
回覆:73
積分:23
註冊:2004-11-30

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-12-16 16:00:40 IP:219.131.xxx.xxx 未訂閱
好的,謝謝!
系統時間:2024-05-20 11:56:55
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!