Softtech
asked on
TStringGrid quick erase
I was looking to quickly erase a populated TStringGrid, and had thought I'd find a .Erase method, but it appears such a method does not exist. Is there a quick was to erase the contents of the cells in a TStringGrid without havig to use a For/Next loop (which would have to iterate through all the cells and erase them)?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hello,
May I ask you why you only give me a B ?
Did you not liked the answer ?
the best answer would be :
procedure TForm1.BitBtn1Click(Sender : TObject);
var
OldRowCount:integer;
begin
//save the rowcount for restoring later
OldRowCount:=StringGrid1.R owCount;
//clear the whole lines at once
StringGrid1.RowCount := StringGrid1.FixedRows + 1;
StringGrid1.Rows[StringGri d1.FixedRo ws].Clear;
StringGrid1.RowCount:=OldR owCount+St ringGrid1. FixedRows ;
end;
I'm asking you so I can enhance what I say next time...
CU
May I ask you why you only give me a B ?
Did you not liked the answer ?
the best answer would be :
procedure TForm1.BitBtn1Click(Sender
var
OldRowCount:integer;
begin
//save the rowcount for restoring later
OldRowCount:=StringGrid1.R
//clear the whole lines at once
StringGrid1.RowCount := StringGrid1.FixedRows + 1;
StringGrid1.Rows[StringGri
StringGrid1.RowCount:=OldR
end;
I'm asking you so I can enhance what I say next time...
CU
ASKER
I must have been in a bad mood when I graded you with a "B". Sorry.
Ok, no problem then...
CU
CU
e.g.
FOR iCount := 0 TO (Grid.ColCount - 1)
DO
Grid.Cells[iCount, 1] := '';
FOR iCount := 1 TO (Grid.RowCount - 1)
DO
Grid.Rows[iCount] := Grid.Rows[1];
This basically wipes the first row (ignoring the top row which might contain titles) and then copies that row into all the rest. Not ideal but a bit quicker
The Neil =;)