Re: StringGrid Frustration

Posted by Bill DelphiMan on June 29, 2007

In Reply to StringGrid Frustration posted by Peter Howes on June 29, 2007

: Hi All
: I'm sure there's a simple solution to this problem, but at present I cannot find it!

: When I fill a stringgrid on a form with data, one cell (normally top-left) is highlighted in blue. For appearance purposes I would like this not to happen. I've tried setting the tab stop to 0 and a few other things relating to the focus but it keeps happening.
: Is there something simple I am missing?
: Thanks.

This is in the Delphi Help file:

"Cells with input focus are drawn the with a special highlight color, just like selected cells without input focus. If goDrawFocusSelected is not included, the cell with input focus is distinguished by a focus rectangle, not by a special background color."

That's OK for a stringgrid that has "focus", but if you also have other component(s) on the form that can have "focus", something strange happens... The standard behavior of a stringgrid that does NOT have focus, is: selected cell is shown with the system default *highlight* colors, usually white text on dark blue background.

Seems that only way to avoid "highlight" coloring is to redraw cell in "standard" colors ourselves, in OnDrawCell event handler:

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
  with StringGrid1.Canvas do begin
    Brush.Color := StringGrid1.Color;
    Font.Color := StringGrid1.Font.Color;
    TextOut(Rect.Left + 2, Rect.Top + 2, StringGrid2.Cells[ACol, ARow]);

Related articles


Follow Ups