在使用StringGrid时,如何实现下面的界面:
我数据库里有20个数据需要在20个StringGrid的单元格里面显示,StringGrid的Col是12,Row是2
也就是第2行就会出现4个空的Cell。
我如何做到第一行我显示12个
第二行我只显示8个? 多谢

解决方案 »

  1.   

    除非你去改 TCustomGrid类的Paint 事件
      

  2.   

    前题:
    1.第一行显示12个数据.
    2.第二行显示8个数据.代码:procedure TForm1.btn1Click(Sender: TObject);
    var
    i:Integer;
    begin
    {qry1 是ADOQUERY控件,strngrd1 是StringGrid控件}
    with qry1 do begin
      if SQL.Text='' then Exit;
      if not Active then Open;
      for i:=1 to 12 do begin
        strngrd1.Cells[i,1]:=FieldByName('cPSCode').AsString;
        Next;
      end;  for i:=1 to 8 do begin
        strngrd1.Cells[i,2]:=FieldByName('cPSCode').AsString;
        Next;
      end;
    end;
    end;
      

  3.   

    是排列数据的话,就如2楼如果是显示网格的话
    procedure TForm1.SG3DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    var
      R: TRect;
    begin
      if (ACol > 7) and (ARow > 1) then         // 如果没有列头的话, ARow > 0
      with TStringGrid(Sender).Canvas do
      begin
        R.Left:= Rect.Right - 2;
        R.Right:= Rect.Right + 2;
        R.Top:= Rect.Top;
        R.Bottom:= Rect.Bottom;
        Brush.Color := clWhite;
        FillRect(R);
        TextOut(R.Left, R.Top, TStringGrid(Sender).Cells[ACol, ARow]);
        R.Left:= Rect.Left;
        R.Right:= Rect.Right;
        R.Top:= Rect.Bottom - 2;
        R.Bottom:= Rect.Bottom + 2;
        Brush.Color := clWhite;
        FillRect(R);
        TextOut(R.Left, R.Top, TStringGrid(Sender).Cells[ACol, ARow]);
      end;
    end;