TStringGrid使用(1)[3]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 cureshy 的 blog

edit1.text := inttostr(adoquery1.recordset.pagecount);
showdata(spinedit2.value);
end;

//然后将absolutepage的数据乾坤大挪移到stringgrid1中
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的程序源码这段代码没有看懂,但是可能有的朋友需要,所以共享一下子 :)
procedure tform1.speedbutton11click(sender: tobject);
var
index_r ,aleft: integer;
index : integer;
begin
stringgrid_file('d:\aaa.txt');
if not linktextfile then
begin
  showmessage('失败');
  exit;
end;
//
quickrep1.dataset := adotable1;
index_r := resize(stringgrid1.width);
aleft := 13;
create_title(titleband1,aleft,24,headercontrol1.sections.items[0].width,20,
  headercontrol1.sections[0].text,taleftjustify);
with create_qrdbtext(detailband1,aleft,8,stringgrid1.colwidths[0],20,
    stringgrid1.font,taleftjustify) do
begin
  dataset := adotable1;
  datafield := adotable1.fields[0].displayname;
end;
aleft := aleft + stringgrid1.colwidths[0] * index_r + index_r;
for index := 1 to adotable1.fieldcount - 1 do
begin
  create_vline(titleband1,aleft - 13,16,1,40);
  create_title(titleband1,aleft,24,headercontrol1.sections.items[index].width,20,
   headercontrol1.sections[index].text,taleftjustify);
  create_vline(detailband1,aleft - 13,-1,1,31);
  with create_qrdbtext(detailband1,aleft ,8,stringgrid1.colwidths[index] * index_r,20,
    stringgrid1.font,taleftjustify) do
  begin
   dataset := adotable1;
   datafield := adotable1.fields[index].displayname;
  end;
  aleft := aleft + stringgrid1.colwidths[index] * index_r + index_r;
end;
quickrep1.preview;
end;

function tform1.resize(agridwidth: integer): integer;
begin
result := trunc(718 / agridwidth);
end;

function tform1.stringgrid_file(afilename: string): boolean;
var
strvalue : string;
index : integer;
acol , arow : integer;
afilevalue : system.textfile;
begin
strvalue := '';
try
  assignfile(afilevalue , afilename);
  rewrite(afilevalue);
  strvalue := headercontrol1.sections[0].text;
  for index := 1 to headercontrol1.sections.count - 1 do
   strvalue := strvalue + ',' + headercontrol1.sections[index].text;
  writeln(afilevalue,strvalue);
  strvalue := '';
  for arow := 0 to stringgrid1.rowcount - 1 do
  begin
   strvalue := '';
   strvalue := stringgrid1.cells[0,arow];
   for acol := 1 to stringgrid1.colcount - 1 do
   begin
    strvalue := strvalue + ', ' + stringgrid1.cells[acol,arow];
   end;
   writeln(afilevalue,strvalue);
  end;
finally
  closefile(afilevalue);
end;
end;

function tform1.linktextfile: boolean;
begin
result := false;
with adotable1 do
begin
  {connectionstring := 'provider=microsoft.jet.oledb.4.0;' +
            'data source= d:\;extended properties=text;' +
            'persist security info=false';
  tablename := 'aaa#txt';
  open;    }
  if active then
   result := true;
end;
end;

function tform1.create_qrdbtext(sender: twincontrol; aleft, atop, awidth,
ahight: integer; afont: tfont; aalignment: talignment): tqrdbtext;
var
aqrdbtext : tqrdbtext;
begin
aqrdbtext := tqrdbtext.create(nil);
with aqrdbtext do
begin
  parent := sender;
  left := aleft;
  top := atop;
  width := awidth;
  height := ahight;
  alignment := aalignment;
  font.assign(afont);
end;
result := aqrdbtext;
end;

function tform1.create_vline(sender: twincontrol; aleft, atop, awidth,
ahight: integer): tqrshape;
var
aqrshapev : tqrshape;
begin
aqrshapev := tqrshape.create(nil);
with aqrshapev do
begin
  parent := sender;
  left := aleft;
  top := atop;
  width := awidth;
  height := ahight;
end;
result := aqrshapev;
end;

procedure tform1.create_title(sender: twincontrol; aleft, atop, awidth,
ahight: integer; acaption: string; aalignment: talignment);
var
aqrlabel : tqrlabel;
begin

本文关键:TStringGrid使用(1)
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top