2007. december 9., vasárnap

Change fonts between columns in a TStringGrid (2)


Problem/Question/Abstract:

How can I code the Fixed Row in Bold (font) style whereas Normal Rows in Normal style for TStringGrid component?

Answer:

You need to handle the OnDrawCell event.

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  Fmt: integer;
begin
  StringGrid1.Canvas.FillRect(Rect);
  {set bold for fixed cells, also set alignment}
  if gdFixed in State then
  begin
    StringGrid1.Canvas.Font.Style := [fsBold];
    Fmt := DT_SINGLELINE or DT_VCENTER or DT_CENTER;
  end
  else
    Fmt := DT_SINGLELINE or DT_VCENTER or DT_LEFT;
  DrawText(StringGrid1.Canvas.Handle, PChar(StringGrid1.Cells[ACol, ARow]), -1, Rect,
    Fmt);
end;

Nincsenek megjegyzések:

Megjegyzés küldése