Solved

Clear all rows in a TStringGrid ??

Posted on 1999-01-15
15
1,111 Views
Last Modified: 2008-03-17
How can i clear some or all rows in a tstringgrid.

I dont want to use the command 'stringgrid1.rows[xx].clear'.
0
Comment
Question by:PeterLarsen
[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
  • 5
  • 4
  • 2
  • +2
15 Comments
 

Expert Comment

by:Tulip
ID: 1356786
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
 
LVL 3

Expert Comment

by:williams2
ID: 1356787
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
 
LVL 20

Expert Comment

by:Madshi
ID: 1356788
Hmmm. Why not?
0
Independent Software Vendors: 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!

 
LVL 20

Expert Comment

by:Madshi
ID: 1356789
I meant, why don't you want to use 'stringgrid1.rows[xx].clear'?
0
 

Expert Comment

by:Tulip
ID: 1356790
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
 
LVL 2

Author Comment

by:PeterLarsen
ID: 1356791
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
 

Expert Comment

by:Tulip
ID: 1356792
Well, then destroy grid and create a new one .
0
 
LVL 2

Author Comment

by:PeterLarsen
ID: 1356793
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
 

Expert Comment

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

Tulip
0
 

Expert Comment

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

Tulip
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 50 total points
ID: 1356796
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
 
LVL 3

Expert Comment

by:williams2
ID: 1356797
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
 
LVL 2

Author Comment

by:PeterLarsen
ID: 1356798
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
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1356799
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
 
LVL 2

Author Comment

by:PeterLarsen
ID: 1356800
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

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

628 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