StringGrid1.Rows.Delete(StringGrid1.Row);

解决方案 »

  1.   

    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
        int l1=StringGrid1->Selection.Top;
        int l2=StringGrid1->Selection.Bottom;
        TStringList *ss=new TStringList();
        for (int c=0;c<StringGrid1->ColCount;c++)
           {
               ss->Clear();
               ss->AddStrings(StringGrid1->Cols[c]);
               for (int L=l1;L<=l2;L++)
                  {
                     ss->Delete(l1);
                     ss->Add("");
                  }
               StringGrid1->Cols[c]=ss;
           }
        delete ss;    TGridRect myRect={l1,0,l1,0};
        StringGrid1->Selection=myRect;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
        for (int x=0;x<StringGrid1->ColCount;x++)
          for (int y=0;y<StringGrid1->RowCount;y++)
              StringGrid1->Cells[x][y]=String(x)+","+String(y);              
    }StringGrid1是古怪不听话的东东,
    连续删行可以了,自已改成DELPHI了,将->要换成 .
      

  2.   

    自己继承一个,就可以使用父类的Delete方法了。
      

  3.   

    procedure TFcx.Btn_clearClick(Sender: TObject);
    VAR I,J,USEFULCOUNT,StartIndex,SELECTCOUNT:INTEGER;
    begin//清除选定的分组行
      //得到非空行的行数
      USEFULCOUNT := 20;//stringgrid.rowcount=20
      FOR I:=0 TO 19 DO
      BEGIN
        IF STRINGGRID1.Cells[0,I]='' THEN
        BEGIN
          USEFULCOUNT := I;
          BREAK;
        END;
      END;
      IF USEFULCOUNT=0 THEN ABORT;
      //得到起始位置和选定的行数
      StartIndex := STRINGGRID1.Selection.Top;
      IF STRINGGRID1.Cells[0,StartIndex]='' THEN ABORT;
      IF STRINGGRID1.Selection.Bottom >= USEFULCOUNT THEN
        SELECTCOUNT:= USEFULCOUNT - StartIndex
      ELSE
        SELECTCOUNT:= STRINGGRID1.Selection.Bottom - StartIndex+1;
      if STRINGGRID1.Selection.Bottom<19 then
      begin  //把选定行之后的全部行前移,覆盖选定的行
       FOR I:=0 TO (USEFULCOUNT - StartIndex - SELECTCOUNT) DO
       BEGIN
        FOR J:=0 TO 3 DO
        BEGIN
          STRINGGRID1.CELLS[J,(StartIndex+I)] := STRINGGRID1.CELLS[J,(StartIndex+SELECTCOUNT+I)];
          FLDARRAY[J,(StartIndex+I)] := FLDARRAY[J,(StartIndex+SELECTCOUNT+I)];
        END;
       END;
      end;
      //清除原来位置的记录
      FOR I:=0 TO SELECTCOUNT-1 DO
      BEGIN
        FOR J:=0 TO 3 DO
        BEGIN
          STRINGGRID1.CELLS[J,(USEFULCOUNT - SELECTCOUNT+I)] := '';
          FLDARRAY[J,(USEFULCOUNT - SELECTCOUNT+I)] := '';
        END;
      END;
    end;
      

  4.   

    windindance,你的方法我试过了,编译不通过。
    '[' excepted but '.' found
      

  5.   

    FRowSelect  定义为单元内变量,值来源:
    在stringgrid的onmouseup过程理写这段代码
    procedure StringGrid2MouseUp(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    var
      RowCnt,ColCnt:integer;
    begin
      if Button =  mbLeft then
      begin
         StringGrid2.MouseToCell(x, y, ColCnt, RowCnt);
         if (RowCnt <> -1) and (ColCnt <> - 1) then FRowSelect := RowCnt;
    end;
    这样就能从你选中的行删除。
    var
      aFarm: integer;
    begin
    with StringGrid1 do
    begin
      //删除应提示,
      Showmessage('您选中的密码条目将被删掉');
      for aFarm := FRowSelect to RowCount - 2 do
      begin
         Rows[aFarm] := Rows[aFarm + 1];
      end;
      Cells[0,RowCount - 1] := '' ;
      Cells[1,RowCount - 1] := '' ;
      Cells[2,RowCount - 1] := '' ;
      Cells[3,RowCount - 1] := '' ;
      RowCount := RowCount - 1;
    end;