TStringGrid.DrawCell - Not Updating The Correct Cell
- From: cyberonix@xxxxxxxxxxx
- Date: 27 Mar 2006 15:53:06 -0800
I have a problem that I've been trying to fix for a couple of days now
without success. I have a standard string grid with DefaultDrawing set
to False and it's double buffered. It has 1 column and 25 rows of which
15 are visible with no scroll bars. All the cells are painted black
with the exception of row 7 which is red. I want to keep this cell red
at all times so I have the following code in the DrawCell event:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow:
Integer;
Rect: TRect; State: TGridDrawState);
begin
if ARow = StringGrid1.TopRow + 7 then
begin
StringGrid1.Canvas.Brush.Color := clRed;
StringGrid1.Canvas.FillRect(Rect);
end
else
begin
StringGrid1.Canvas.Brush.Color := clBlack;
StringGrid1.Canvas.FillRect(Rect);
end;
end;
Here's the problem. When the grid rows shift up or down the wrong cell
gets painted. If I'm scrolling down then the red cell travels up to the
top of the control each time I move down one. Conversely if I move up
then the red cell moves down towards the bottom. I thought it might be
a timing issue of the grid getting painted and then being shifted so I
added this code to the TopLeftChanged event:
procedure TForm1.StringGrid1TopLeftChanged(Sender: TObject);
begin
StringGrid1.Repaint;
end;
This seems to fix the problem for the most part BUT what happens is
when scrolling fast through the cells you occasionally see the column
directly above or directly below (depending on which way I'm scrolling)
flicker with red and then jump to row 7.
I know it's minor but there must be a way to prevent this. Any help
would be appreciated.
Thanks,
Jason
.
- Prev by Date: Re: array with same value all the time?
- Next by Date: Re: Fast Track towards using an existing application on the Internet
- Previous by thread: array with same value all the time?
- Next by thread: Re: TStringGrid.DrawCell - Not Updating The Correct Cell
- Index(es):
Relevant Pages
|