如何select 然后删除Delphi 中TStringGrid 中的单元格?

How to select and then delete cell in TStringGrid in Delphi?

我知道如何将数据输入网格,但我还需要为 selected 行制作删除按钮。我一直在寻找扔互联网,几乎一无所获。如何删除东西,我只是找不到如何 select 特定单元格,然后如何 edit/delete 或对她做任何事情。 这是我的意思的例子:

我 select 通过鼠标或任何 1 个单元格,然后它 selects (例如)这个单元格所在的整行。之后我点击按钮删除。如何告诉删除函数哪一行被 selected.

找到一个答案:

创建程序:

procedure StringGridDeleteRow( AStringGrid:TStringGrid; ARow:integer );
var
  nRow:integer;
begin
  with AStringGrid do
    begin
      for nRow := ARow to RowCount - 2 do
        Rows[nRow].Assign(Rows[nRow+1]);
      Rows[RowCount-1].Clear;
      RowCount := RowCount - 1
    end;
end;

然后将此行添加到您的按钮中:

StringGridDeleteRow(StringGrid1, StringGrid1.Row);

比我想象的要容易!