Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Clear all rows in a TStringGrid ??

Posted on 1999-01-15
15
Medium Priority
?
1,120 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
  • 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 150 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

Industry Leaders: 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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

972 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