起步软件技术论坛-X3

 找回密码
 立即注册
搜索
查看: 89|回复: 2

【结贴】关于StringGird的问题**

[复制链接]
发表于 2007-11-20 17:48:45 | 显示全部楼层 |阅读模式
StringGird没有addrow方法了吗?
回复

使用道具 举报

 楼主| 发表于 2007-11-20 18:11:29 | 显示全部楼层
结贴吧
回复 支持 反对

使用道具 举报

发表于 2007-11-21 10:36:43 | 显示全部楼层
贴一段TStringGrid的代码看看吧
========================================
function GetFieldSize(AField: TDataField): Integer;
begin
  case AField.DataType of
    TFieldType.ftBoolean:
        Result := 20;
    TFieldType.ftDate, TFieldType.ftDateTime, TFieldType.ftTime:
        Result := 20;
    TFieldType.ftInteger, TFieldType.ftLargeint, TFieldType.ftSmallint:
        Result := 20;
    TFieldType.ftFloat:
        Result := 20;
    else
        Result := AField.Size;
  end;
  if Result<Length(AField.FieldName) then Result := Length(AField.FieldName);
end;


var
  i, j: Integer;
begin
  sgrdResult.ColCount := ADataSet.FieldCount+1;
  sgrdResult.RowCount := ADataSet.RecordCount+1;

  sgrdResult.ColWidths[0] := sgrdResult.Font.Size * 2;
  for i:=0 to ADataSet.FieldCount-1 do
  begin
    sgrdResult.Cells[i+1, 0] := ADataSet.Fields.FieldName;
    sgrdResult.ColWidths[i+1] := sgrdResult.Font.Size * GetFieldSize(ADataSet.Fields) ;
  end;

  j:=0;
  ADataSet.First;
  while not ADataSet.Eof do
  begin
    Inc(j);
    sgrdResult.Cells[0, j] := SysUtils.IntToStr(j);
    for i:=0 to ADataSet.FieldCount-1 do
      sgrdResult.Cells[i+1, j] := ADataSet.Fields.AsString;

    ADataSet.Next;
  end;
end;
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Justep Inc.

GMT+8, 2025-7-1 02:24 , Processed in 0.037291 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表