Delphi 的StringGrid 如果在添加数据时增加行。请大家指教。

解决方案 »

  1.   

    要看你怎么增加法了.如果是最后加,你看楼上的.
    如果是中间插入方式的,就是先增一,然后把原来行的内容都移到下面一行去.
    ========================================================
    void __fastcall  Tfm_ly_bill::InsertRow(TStringGrid *tmp_sg,int row,int type)  //type=0为ROW的前一行 =1为ROW的后一行
    {
    //  if(row>=tmp_sg->RowCount)  row=tmp_sg->RowCount-1;
      tmp_sg->RowCount++; //行增一
      int   i,j;
      for(i=tmp_sg->RowCount;i>row+type;   i--)  //数据依次后移
      {
        for(j=0;   j<tmp_sg->ColCount;   j++)
          tmp_sg->Cells[j][i]=tmp_sg->Cells[j][i-1];
      }
      for(j=1;j<tmp_sg->ColCount;   j++) //清除插入一行的数据
      {
        tmp_sg->Cells[0][i]="*";
        tmp_sg->Cells[j][i]="";
        tmp_sg->Row=i;
        tmp_sg->Col=5;
      }
    }