Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

TStringGrid quick erase

Posted on 2000-04-19
5
Medium Priority
?
281 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 150 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

722 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