数据表 dd 
字段1.rom:  0101 0102.... 0140,0201..0220..0240 
    2.STA: VR  VD VC VM OO 
如何将这么多的数据在STRINGGRID上显示,且能控制STRINGGRID一行可以显示几个(15个),或者说满足条怎么换行显示,请各位大侠帮帮忙,如果有西安的朋友可以留下联系方式,搞定我请吃饭 
                              

解决方案 »

  1.   

    先用字符串存rom, STA两个字段的值,再分别存到StringList里,然后再按要求分别合成两个字符串,显示在stringgrid
    代码参考:uses StrUtils;var
      rom, STA: string;
      romList, STAList: TStrings;
      ResultRom, ResultSTA: string;
      i: Integer;
    begin
      ...  //数据库查询部分
      rom := adoQuery1.FieldByName('rom').AsString;
      STA := adoQuery1.FieldByName('STA').AsString;
      romList := TStringList.Create;
      STAList := TStringList.Create;
      romList.Text := AnsiReplaceStr(rom, ' ', #10);  //假定rom字段值用空格分隔
      STAList.Text := AnsiReplaceStr(STA, ' ', #10);
      ResultRom := '';
      ResultSTA := '';
      for i := 0 to romList.Count - 1 do
      begin
        ResultRom := ResultRom + romList[i] + ' ';
        if (i >= 15) and (i mod 15 = 0) then //一行显示15个
          ResultRom := ResultRom + #13#10;
      end;
      for i := 0 to STAList.Count - 1 do
      begin
        ResultSTA := ResultSTA + STAList[i] + ' ';
        if (i >= 15) and (i mod 15 = 0) then //一行显示15个
          ResultSTA := ResultSTA + #13#10;
      end;
      StringGrid.Cells[0, 0] := ResultRom;  //StringGrid第0列0行显示ResultRom
      StringGrid.Cells[1, 0] := ResultSTA;  //StringGrid第1列0行显示ResultSTA
    end;以上是大致的代码。
      

  2.   

    给你个开头控制sg的例子 控制列高,列数什么的 ,然后数据就是循环的一行一行,一个字段一个字段的写入的var
    i,RowNum,j:integer;
    begin
      with SG  do
      begin
        RowHeights[0]:=18;
        RowHeights[1]:=24;
        RowCount:=2;
        ColCount := 16   ;
        Cells[0,0]:='地区';
        cells[1,0]:='用户种类';
        Cells[2,0]:='性质';
        Cells[3,0]:='用电类别';
        Cells[4,0]:='本月应收';
        Cells[5,0]:='往月欠收';
        cells[6,0] := '上月余额';
        Cells[7,0]:='累计应收';
        cells[8,0] := '本月实收';
        Cells[9,0]:='预交款';
        Cells[10,0]:='自动冲帐';
        cells[11,0] := '本月欠收';
        cells[12,0]:='累计欠收';
        cells[13,0]:='滞纳金';
        cells[14,0]:='短信费用';
         cells[15,0]:='误差';    ColWidths[2] := 50 ;
        ColWidths[3] := 70 ;
        ColWidths[4] := 100 ;
        ColWidths[5] := 100 ;
        ColWidths[6] := 100 ;
        ColWidths[7] := 100 ;
        ColWidths[8] := 100 ;
        ColWidths[9] := 100 ;
        ColWidths[10] := 100 ;
        ColWidths[11] := 100 ;
        ColWidths[12] := 100 ;
        ColWidths[13] := 100 ;
        ColWidths[14] := 100 ;
        ColWidths[15] := 100 ;
        for RowNum:=1 to 30  do
        begin
          Cells[0,RowNum]:='';
          Cells[1,RowNum]:='';
          Cells[2,RowNum]:='';
          Cells[3,RowNum]:='';
          cells[4,RowNum] := '';
          Cells[5,RowNum]:='';
          cells[6,RowNum] := '';
          Cells[7,RowNum]:='';
          Cells[8,RowNum]:='';
          cells[9,RowNum] := '';
          cells[10,RowNum]:='';
          cells[11,RowNum]:='';
          cells[12,RowNum]:='';
          cells[13,RowNum]:='';
           cells[14,RowNum]:='';
           cells[15,RowNum]:='';
       end;
      end;with adoquery  do
        i := 1  ;
        while not eof do
          sg.Cells[0,i] := fieldvalues['a'];
          sg.Cells[2,i] := fieldvalues['b'];
       //     .....等等 i为行
           next ;
          i := i+1  ;
        end;
    end;
      

  3.   

    var 
      rom, STA: string; 
      romList, STAList: TStrings; 
      ResultRom, ResultSTA: string; 
      i: Integer 
    begin 
      adoq11.ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=myhis'; 
      with adoq11 do 
        begin 
          close; 
          sql.Clear; 
          sql.Add('select * from myrom'); 
          open; 
          rom:=trim(fieldByName('rom').AsString); 
          sta:=trim(fieldByName('sta').AsString); 
          romList := TStringList.Create; 
          STAList := TStringList.Create; 
          romList.Text :=trim(fieldByName('rom').AsString); 
          STAList.Text := trim(fieldByName('sta').AsString); 
          //romList.Text :=AnsiReplaceStr(rom,'',#10); 
          //AnsiReplaceStr(rom, ' ', #10);  //假定rom字段值用空格分隔 
          //STAList.Text := AnsiReplaceStr(STA, ' ', #10); 
          ResultRom := ''; 
          ResultSTA := ''; 
        // rom:=trim(fieldByName('rom').AsString); 
        //  sta:=trim(fieldByName('sta').AsString); 
        for i := 0 to romList.Count - 1 do 
        begin 
          ResultRom := ResultRom + romList[i] + ' '; 
          if (i >= 15) and (i mod 15 = 0) then //一行显示15个 
          ResultRom := ResultRom + #13#10; 
        end; 
        for i := 0 to STAList.Count - 1 do 
        begin 
          ResultSTA := ResultSTA + STAList[i] + ' '; 
          if (i >= 15) and (i mod 15 = 0) then //一行显示15个 
          ResultSTA := ResultSTA + #13#10; 
        end; 
      sgd1.Cells[0, 0] := ResultRom;  //StringGrid第0列0行显示ResultRom 
      Sgd1.Cells[1, 0] := ResultSTA;  //StringGrid第1列0行显示ResultSTA 
      end; 
    上面的哥们,AnsiReplaceStr这个用不了函数,还有就是不循环,只显示一个0301怎么回事啊