2010. december 9., csütörtök

Clear a TStringGrid


Problem/Question/Abstract:

I have a form with a stringgrid on it. I use the grid to display some data regarding a certain part. How do I clear the grid, that still holds data from the first display, before I display data of a different part?

Answer:

You have to loop over the rows or cols or even cells (depends on how the grid is layed out):

with StringGrid1 do
begin
  perform(WM_SETREDRAW, 0, 0); {block visual updates}
  try
    for i := fixedRows to Rowcount - 1 do
      Rows[i].Clear;
  finally
    perform(WM_SETREDRAW, 1, 0);
    invalidate;
  end;
end;

Since this wipes complete rows it would not be suitable if you have a fixed column on the left that should be preserved, for example.

Nincsenek megjegyzések:

Megjegyzés küldése