Board index » delphi » TStringGrid: Hide/Show Last Column

TStringGrid: Hide/Show Last Column

This works, but I don't think it should! (So why am I complaining?)

I filled a string grid with data. I added a button to hide or show the
last column, which simply decrements or increments ColCount. After
decrementing and then incrementing ColCount, the data in the last
column is still there. I expected it to be gone.

I added a status bar to show Rows[2].Count each time I add or delete
the last column, and it accurately reflects the changing
TStrings.Count.

Why is the data still there? Can I safely use this to temporarily hide
and show the last column, which is what I want to do? It worries me
that the data is still there when I expected it to disappear.

 

Re:TStringGrid: Hide/Show Last Column


Quote
In article <8h3c5b$d...@bornews.borland.com>, Richard Simpson wrote:
> I filled a string grid with data. I added a button to hide or show the
> last column, which simply decrements or increments ColCount. After
> decrementing and then incrementing ColCount, the data in the last
> column is still there. I expected it to be gone.

This is due to a performance optimization done in the storage (a sparse
array class) used by the grid to store its data. If you want to actually
delete the data you have to call Cols[ colcount-1 ].Clear before reducing
the column count. Otherwise the spares array class will only delete the
data when the slot is reused or a whole "cell bucket" is discarded.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Other Threads