Как удалить строку в StringGrid в run-time?
Материал из DRKB
Как удалить строку в StringGrid в run-time?[править | править код]
Можно сделать наследника от TCustomGrid. А у последнего есть метод - DeleteRow.
Author: Song
Source: Взято с Vingrad.ru http://forum.vingrad.ru
ID: 00591
Например удаление текущей строки:
type TFakeGrid = class(TCustomGrid);
procedure TForm1.MyDelete(Sender: TObject);
begin
TFakeGrid(Grid).DeleteRow(Grid.Row);
end;
Примечание от bur80 (Sources.ru):
Предлагаю в разделе VCL -> StringGrid внести корректировочку в статью "Как удалить строку в StringGrid в run-time", что данный метод(!) будет работать только в случае если форма создаётся вот так:
Form1.ShowModal;
а не так:
var
fr1: TForm1;
begin
fr1 := Tform1.Create(Application);
fr1.Show;
end;
Author: Vit (www.delphist.com, www.drkb.ru, www.unihighlighter.com, www.nevzorov.org)
Source: Взято с Vingrad.ru http://forum.vingrad.ru
ID: 00593
{ **** UBPFD *********** by delphibase.endimus.com ****
>> Удаление строки из StringGrid
Удаляет из StringGrid указанную строку, сдвигая остальные.
Зависимости: Grids
Copyright: MBo
Дата: 27 апреля 2002 г.
***************************************************** }
procedure SGDeleteRow(SG: TStringGrid; RowToDelete: Integer);
var
i: Integer;
begin
with SG do
begin
if (RowToDelete >= 0) and (RowToDelete < RowCount) then
begin
for i := RowToDelete to RowCount - 2 do
Rows[i].Assign(Rows[i + 1]);
RowCount := RowCount - 1;
end;
end;
end;
Source: http://delphibase.endimus.com
ID: 01049
procedure GridDeleteRow(RowNumber: Integer; Grid: TstringGrid);
var
i: Integer;
begin
Grid.Row := RowNumber;
if (Grid.Row = Grid.RowCount - 1) then
{ On the last row}
Grid.RowCount := Grid.RowCount - 1
else
begin
{ Not the last row}
for i := RowNumber to Grid.RowCount - 1 do
Grid.Rows[i] := Grid.Rows[i + 1];
Grid.RowCount := Grid.RowCount - 1;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
GridDeleteRow(3, stringGrid1);
end;
Source: Взято с сайта: http://www.swissdelphicenter.ch
ID: 01050