stringgrid中随便在某行中增加一行,并且原有的数据不丢失,我的数据不是数据库中的数据。
就象是在Excel表格一样中右键选增加一行就增加了一行并且原来的数据会自动向下移动

解决方案 »

  1.   

    StringGrid1->RowCount++;
    int i=StringGrid1->Row;
    for(int j=StringGrid1->Row-1;j>=i;j--)
       //循环复制内容,然后再把那行清空
      

  2.   

    太麻烦,建议用DevExpress.SpreadSheet 控件,和EXCEL几乎一模一样。很多地方可以下,搜索一下
      

  3.   

    好简单,我做过,分数全部给我啦.........
    var
      i: Integer;
      //先增加一行
      sgWords.RowCount := sgWords.RowCount + 1;
      sgWords.Rows[sgWords.RowCount - 1].Clear;
      //移形换位,把最后一行跟你指定的行换位置!
      CurrentRow := sgWords.Row;
      for i := sgWords.RowCount - 1 downto CurrentRow + 1 do
      begin
        sgWords.Rows[i].Assign(sgWords.Rows[i - 1]);
      end;
      sgWords.Rows[CurrentRow].Clear;
      sgWords.Row := CurrentRow;
      SendMessage(sgWords.Handle, EM_SCROLLCARET, 0, 0);//多送你一个方法:滚动到插入行的位置
      

  4.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons, Grids;type
      TForm1 = class(TForm)
        StringGrid1: TStringGrid;
        BitBtn1: TBitBtn;
        procedure FormCreate(Sender: TObject);
        procedure BitBtn1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;type tgridex = class(TStringGrid)
    end;var
      Form1: TForm1;
    implementation{$R *.dfm}
    // ToIndex是你要在strgrid插入行的INDEX
    procedure stringgridadd(strgrid:TStringGrid;ToIndex:integer);
    begin
        strgrid.RowCount:=strgrid.RowCount+1;
        tgridex(strgrid).MoveRow(strgrid.RowCount,ToIndex+1);
    end;procedure TForm1.FormCreate(Sender: TObject);
    var i,j:integer;
    begin
         StringGrid1.RowCount:=12;
         StringGrid1.ColCount:=12;
         StringGrid1.Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goRowSelect];
         for i:=1 to  10 do
         begin
            for j:=1 to 10 do
            begin
              StringGrid1.Cells[j,i]:=Format('%d,%d',[i,j]);
            end;
         end;
    end;procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
          stringgridadd(StringGrid1,1); //在第一行后插入
    end;end.
      

  5.   

    wanbb (wanbb) ,刚测试通过。