🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #1677

Re: Best way to clear a stringgrid?

#1677
From: Remy Lebeau (TeamB)
Date: Thu, 28 Jun 2007 16:23
58 lines
2845 bytes
"Dan" <Dan@do.not.spam> wrote in message
news:4683bbbe$1@newsgroups.borland.com...

> What is the best way to do that?

There are three ways to "clear" a TStringGrid:

1) If you want to remove all of the rows, then set the RowCount
property to (FixedRows+1) and then Clear() the remaining row by
itself.  A TStringGrid must always have at least 1 non-fixed row at
all times.  The RowCount cannot be set to 0.  Don't ask me why, I
don't know why Borland designed TStringGrid that way.

2) If you do not want to remove all of the rows, then either:

    a) loop through the Rows[] list calling Clear() on each one

    b) loop through the Cells[][] property (which ou are doing)

> The problem that I am having is that for REALLY LARGE grids,
> clearing the grid takes a long time.  I'd like to see quick
performance
> like I see when I close the app.

Then I suggest not using a TStringGrid at all.  A TListView in virtual
mode (OwnerData = true) would be a lot faster, not to mention have a
cleaner look in general.

> Would it be best to delete the grid and recreate it instead?

Not really.

> This is my code:

It is not necessary to loop through the Cells[][] and Objects[][]
properties as well as set the Row/ColCount properties at the same time
like you are doing.  Simply setting the Row/ColCount is enough to
remove all of the affected cell values just fine.

> //this process is slow, but needed
> //if I don't do this, and just change the col/row counts
> //then the cells may still have values.

That is not true.  All rows/columns that are removed are freed from
memory.  There is nothing physically available for the TStringGrid to
keep displaying for them.

Try this:

    void ClearStringGrid(TStringGrid* sgGrid)
    {
        sgGrid->RowCount = (sgGrid->FixedRows+1);
        sgGrid->Rows[sgGrid->FixedRows]->Clear();
    }


Gambit
Technical Details
Message-ID: <4683e2e7$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4683bbbe$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,dbe415a5e9add767
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4683bbbe$1@newsgroups.borland.com>
Subject: Re: Best way to clear a stringgrid?
Date: Thu, 28 Jun 2007 09:23:40 -0700
Lines: 60
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 75.82.252.126
Message-ID: <4683e2e7$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1183048423 75.82.252.126 (28 Jun 2007 09:33:43 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail