Solved

TStringGrid quick erase

Posted on 2000-04-19
5
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month4 days, 11 hours left to enroll

635 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