数据表 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.   

    用数据集取出数据。
    然后循环,StringGrid.Cells[X, Y] := ADOQUERY.FieldByName('').AsString := 
      

  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怎么回事啊