delphi中如何删除stringgrid中的某行数据

解决方案 »

  1.   

    var 
      krow:integer;stringgrid1.onselectcell()
      begin
    krow:=arow;
    end;var
      i:integer;
    begin
    for i:=0 to stringgrid1.colcount-1 do
      stringgrid1.cells[i,krow]:=''
    end;
      

  2.   

    给你一段代码,可行的
    procedure TfrmEmployEdit.btnDelClick(Sender: TObject);    //删除
    var
      i, n : Integer;
      strID  : string;
      temp : Pchar;
    begin
      inherited;
      temp := pchar('您是否确定要删除编号为【'+StrGridDate.Cells[1, StrGridDate.Row]+ '】的巡检员?');  if messagebox(self.Handle, temp, '警告',MB_yesno or MB_ICONQUESTION )=IDyes then
      begin
        StrID := StrGridDate.Cells[1, StrGridDate.Row];
        for i:= StrGridDate.row to StrGridDate.RowCount do
          for n:=1 to 10 do
            StrGridDate.Cells[n,i] := StrGridDate.Cells[n, i+1];
        StrGridDate.RowCount:= StrGridDate.RowCount - 1;    for i:=1 to StrGridDate.RowCount-1 do
          StrGridDate.Cells[0,i] := IntToStr(i);//这只是删除表面的    with QryMain do
        try
          begin
            Clear;
            Add('delete from xg_Employ where EmpNo = '''+StrID+'''');
            ExecSQL;
            Close;
          end;
        except
          on E : Exception do
          begin
            MessageDlg(E.Message , mtError, [mbOK], 0);
          end;
        end;
        intCount := IntCount - 1;
        LCount.Caption := '共有巡检员记录 :'+''+IntToStr(intCount)+''+'条';
      end;  
    end;
      

  3.   

    声明一个TCustomGrid的子类  TmyStringGrid = class(TCustomGrid)
      public
        procedure DeleteRow(Arow:Integer);override;
      end;在implementation部分加上procedure TmyStringGrid.DeleteRow(Arow:Integer);
    begin
      inherited;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
    TmyStringGrid(StringGrid1).DeleteRow(StringGrid1.Row);
    end;这样点击Button2就可以删除当前行了.