Solved

TStringGrid quick erase

Posted on 2000-04-19
5
262 Views
Last Modified: 2010-04-04
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)?
0
Comment
Question by:Softtech
  • 3
5 Comments
 
LVL 5

Expert Comment

by:TheNeil
ID: 2731256
You could just iterate through all of the rows
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 =;)
0
 
LVL 4

Accepted Solution

by:
jeurk earned 50 total points
ID: 2731399
Hello,
the fastest way I know would be :

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  StringGrid1.RowCount := StringGrid1.FixedRows + 1;
  StringGrid1.Rows[StringGrid1.FixedRows].Clear;
end;

if you want to leave the rowcount intact just do :
procedure TForm1.BitBtn1Click(Sender: TObject);
var
  i: integer;
begin
  for i := StringGrid1.FixedRows to StringGrid1.RowCount - 1 do
  begin
    StringGrid1.Rows[i].Clear;
  end;
end;

Regards.
0
 
LVL 4

Expert Comment

by:jeurk
ID: 2805372
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.RowCount;
  //clear the whole lines at once
  StringGrid1.RowCount := StringGrid1.FixedRows + 1;
  StringGrid1.Rows[StringGrid1.FixedRows].Clear;
  StringGrid1.RowCount:=OldRowCount+StringGrid1.FixedRows ;
end;

I'm asking you so I can enhance what I say next time...
CU
0
 

Author Comment

by:Softtech
ID: 2806349
I must have been in a bad mood when I graded you with a "B".  Sorry.
0
 
LVL 4

Expert Comment

by:jeurk
ID: 2809809
Ok, no problem then...
CU
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now