比如要删除,含有‘啊啊啊啊’字符的行?

解决方案 »

  1.   

    procedure TForm1.FormCreate(Sender: TObject);
    var
      i, j: Integer;
    begin
      for i := 1 to sg.ColCount - 1 do
        for j := 1 to sg.RowCount - 1 do
        begin
          sg.Cells[i, j] := IntToStr(i * j);
          if j mod 2 = 0 then
            sg.Cells[i, j] := '阿'
        end;
    end;procedure TForm1.BitBtn1Click(Sender: TObject);
    var
      i, j, k: Integer;
    begin
      for i := 1 to sg.RowCount - 1 do
        for j := 1 to sg.ColCount - 1 do
          if Pos('阿', sg.Cells[j, i]) > 0 then
          begin
            for k := i to sg.RowCount - 1 do
              sg.Rows[k] := sg.Rows[k + 1];
            sg.RowCount := sg.RowCount - 1;
            Break;
          end
    end;
      

  2.   

    在GRIDS单元中有一个TSparseList类,将该类定义在implementation前并重新编译,
    使用以下语句以可实现上述功能
    TSparseList(StringGrid1.Rows).Delete(RowIndex);
      

  3.   

    如果想删除第n行
    while n < StringGrid.RowCount - 1 do
    begin
      StringGrid.Rows[n] := StringGrid.Rows[n+1];
      Inc(n);
    end;
      

  4.   

    删除当前指定行:
    procedure TForm1.Button8Click(Sender: TObject);
    var i: Integer;
        st: TStringList;
    begin
      st :=  TStringList.Create;
      for i:=0 to StringGrid1.ColCount-1 do begin
        st.Assign(StringGrid1.Cols[i]);
        st.Delete(StringGrid1.Row);
        StringGrid1.Cols[i].Assign(st);
      end;
      StringGrid1.RowCount := StringGrid1.RowCount-1;
      st.Free;
    end;