目前在使用stringgrid,需要动态的往Stringgrid中增加记录,但若Stringgrid中有记录,比如有5行记录了,则增加的记录从6行开始。另外,也需要读取 stringgrid中所有的记录到文本中。。但如何知道Stringrid中的总共在哪几行有记录呢?

解决方案 »

  1.   

    Specifies the number of rows in the grid.
    返回或者指定gird的行数stringgrid.RowCount: Longint;
      

  2.   

    procedure TForm1.FormCreate(Sender: TObject);
    var
      i:Integer;
      a:Integer;
    begin
      a:=0;
      for I:=1 to StringGrid1.RowCount-1 do
      begin
        if StringGrid1.Cells[1,i]<>'' then
          Inc(a);
      end;
    end;
      

  3.   

    for i:=0 to stringGrid.rowCount -1 do
    begin
      if  Trim(StringGrid.Rows[i].Text) = '' then
         result := i;  //返回空的一行,你可以从这行开始写数据
    end;