Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1128
  • Last Modified:

Clear all rows in a TStringGrid ??

How can i clear some or all rows in a tstringgrid.

I dont want to use the command 'stringgrid1.rows[xx].clear'.
0
PeterLarsen
Asked:
PeterLarsen
  • 5
  • 4
  • 2
  • +2
1 Solution
 
TulipCommented:
I don't see another solution then this one:

for i := 0 to StringGrid1.RowCount-1 do StringGrid1.Rows[i].Clear;

But I don't use StringGrid. There is a better one available, called HyperGrid.
There you can call  HyperGrid1.Clear or even define an area (from..to) to clear.

You can find it at:   http://www.pablop.demon.co.uk/


Cheers, Tulip
0
 
williams2Commented:
Their is severel ways to do this

1) You might clear the actual cell texts
2) Set the StringGrid1.RowCount to minimum
3) Set the StringGrid1.ColCount to minimum

To clear all the cell properties do like:

For i:= 0 to StringGrid1.RowCount-1 do
  For j:= 0 to StringGrid1.ColCount-1 do
    StringGrid1.Cells[j,i]:= '';

Regards,
Williams
0
 
MadshiCommented:
Hmmm. Why not?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
MadshiCommented:
I meant, why don't you want to use 'stringgrid1.rows[xx].clear'?
0
 
TulipCommented:
If you have problems with that URL (actually I have them at the moment) then you
can try it at Torry's Delphi Pages:

http://www.torry.ru/vcl/grids/hyperd2.zip  (Delphi 2)
http://www.torry.ru/vcl/grids/hyperd3.zip  (Delphi 3)
http://www.torry.ru/vcl/grids/hyperd4.zip  (Delphi 4)

Cheers, Tulip
0
 
PeterLarsenAuthor Commented:
First, thanks to all. I posted my question 5 min ago...

Tulip : I must use standard components in this project.

William : I want to clear 500000 rows (sometime more). By using 'stringgrid.rows[xx].clear' -it takes too long time to clear so many rows.

Regards
PL
0
 
TulipCommented:
Well, then destroy grid and create a new one .
0
 
PeterLarsenAuthor Commented:
First, thanks to all. I posted my question 5 min ago...

Tulip : I must use standard components in this project.

William : I want to clear 500000 rows (sometime more). By using 'stringgrid.rows[xx].clear' -it takes too long time to clear so many rows.

Regards
PL
0
 
TulipCommented:
Well, then destroy the grid and create a new one. That's brute but fast.

Tulip
0
 
TulipCommented:
Well, then destroy the grid and create a new one. That's brute but fast.

Tulip
0
 
rwilson032697Commented:
I think the solution is not to clear the grid at all if you are dealing with 500,000 rows or more. Treat the grid as a virtual display: ie: set the rowcount of the grid to 500,000 or whatever the number is, but never actually populate the grid cells with strings.

To display strings in the cells override the DrawCell event, like this:

Function MyDataSource(Row, Col : Integer) : String;
begin
  Result := 'Fred'; // You would set it to your required string
end;

procedure TForm3.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  StringGrid1.canvas.TextOut(Rect.left, rect.bottom, MyDataSource(ACol, ARow));
end;

Also, use the GetEditText and SetEditText events to permit the user to edit the data in the cells.

In this way you never have to clear the grid and you save all that time populating it in the first place.

Cheers,

Raymond.

0
 
williams2Commented:
I would say that you'll have to make a custom handing more like having your own datastructure build together with an ownerdrawn grid

Regards,
Williams
0
 
PeterLarsenAuthor Commented:
Hi Raymond and thanks..

Your idea is fine but.... The application-stringgrid reads its data from either a local CDRom or the Internet.
When reading from the Internet, the data has to be stored somewhere in the system (a type of Record or TstringList), otherwise the system is getting very slow. Its takes up memory - each row (4 byte) + each record (?? byte).
I am using OnDrawCell to draw colors others than windows standard colors - so this part i easy.

Your idea may be the only way to do this - i don't know. It takes some re-programming to emplement your idea.
It may also slow down the system to dynamic create+destroy the so many records.

regards, PL
0
 
rwilson032697Commented:
Well, you have to read the information anyway, the only difference is instead of injecting it into the string grid you would store it on disk, or perhaps create a TList descendent that stored objects, each of which stored the information for a row (or you could even use a DynamicArray).

The options are certainly there, though I don't think it would be a lot of work to change it.

Cheers,

Raymond.
0
 
PeterLarsenAuthor Commented:
Well, there are more than 20.000 lines of code in 25 units. I may have to change 10-20 % of the code. :(
But - sometimes you have to change a lot - to make it perfect.

Regards, PL.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now