Mereset String Grid

Berikut ini tips untuk me-reset (mengosongkan) isi dari setia sel dalam strimg grid tanpa mengurangi jumlah kolom dan baris.

Semoga bermanfaat.

procedure ClearGrid(Sender:TForm;GridName: String);
Var I,j,x : Integer;
IRow,ICol : Integer;
begin
For I:= 0 to Sender.ComponentCount – 1 do
Begin
If (Sender.Components[i] is TStringGrid) Then
Begin
If (Sender.Components[i] as TStringGrid).Name = GridName Then
Begin
ICol := (Sender.Components[i] as TStringGrid).ColCount;
IRow := (Sender.Components[i] as TStringGrid).RowCount;
For J:= 1 to IRow-1 do
Begin
For X:=0 to ICol-1 do
Begin
(Sender.Components[i] as TStringGrid).Cells[X,j]:=’ ‘;
End;
End;
(Sender.Components[i] as TStringGrid).RowCount :=2;
End;
End;
End;
end;