Use this file to discover all available pages before exploring further.
TeeGrid provides comprehensive styling capabilities through the TFormat, TTextFormat, TBrush, TStroke, and TFont classes. You can customize colors, borders, fonts, and gradients for individual columns, cells, headers, and the entire grid.
// Disable parent format to use custom formattingTeeGrid1.Columns[0].ParentFormat := False;// Set background colorTeeGrid1.Columns[0].Format.Brush.Color := TColors.Cream;TeeGrid1.Columns[0].Format.Brush.Visible := True;// Set font propertiesTeeGrid1.Columns[0].Format.Font.Size := 11;TeeGrid1.Columns[0].Format.Font.Color := TColors.Navy;TeeGrid1.Columns[0].Format.Font.Style := [fsBold];
Use the OnPaint event to apply formatting based on cell values:
procedure TForm1.Column1Paint(const Sender: TColumn; var AData: TRenderData; var DefaultPaint: Boolean);begin // Highlight negative values in red if StrToFloatDef(AData.Data, 0) < 0 then begin AData.Painter.SetFont(Sender.Format.Font); AData.Painter.SetBrush(Sender.Format.Brush); // Override color Sender.Format.Font.Color := TColors.Red; Sender.Format.Brush.Color := TColors.Pink; end;end;// Assign the eventTeeGrid1.Columns['Amount'].OnPaint := Column1Paint;
TeeGrid1.Grid.Rows.OnPaint := procedure(const Sender: TObject; const ARow: Integer; var AData: TRenderData; var DefaultPaint: Boolean)begin if Odd(ARow) then begin AData.Painter.SetBrush(TeeGrid1.Cells.Format.Brush); TeeGrid1.Cells.Format.Brush.Color := TColorHelper.From(TColors.LightGray, 0.3); end;end;
TeeGrid uses TColor (an alias for TAlphaColor in modern Delphi) which supports opacity:
uses Tee.Format;var Color: TColor;begin // Create color with 50% opacity Color := TColorHelper.From(TColors.Blue, 0.5); // Extract opacity from a color var Opacity := TColorHelper.Opacity(Color); // Returns 0-255 // Remove opacity from a color var SolidColor := TColorHelper.RemoveOpacity(Color);end;
// Configure how lines end and joinwith TeeGrid1.Cells.Format.Stroke dobegin EndStyle := TStrokeEnd.Round; // Round, Square, or Flat JoinStyle := TStrokeJoin.Round; // Round, Bevel, or Mitterend;
Here’s a comprehensive example that styles a financial data grid:
procedure TForm1.StyleFinancialGrid;begin // Grid-wide settings TeeGrid1.Cells.Format.Brush.Color := TColors.White; TeeGrid1.Cells.Format.Font.Name := 'Segoe UI'; TeeGrid1.Cells.Format.Font.Size := 10; // Style the Symbol column with TeeGrid1.Columns['Symbol'] do begin ParentFormat := False; Format.Font.Style := [fsBold]; Format.Font.Color := TColors.Navy; end; // Style the Price column with currency formatting with TeeGrid1.Columns['Price'] do begin ParentFormat := False; Format.Font.Name := 'Consolas'; DataFormat.Float := '$0.00'; end; // Style the Change column with conditional colors TeeGrid1.Columns['Change'].OnPaint := procedure(const Sender: TColumn; var AData: TRenderData; var DefaultPaint: Boolean) var Value: Double; begin Value := StrToFloatDef(AData.Data, 0); Sender.ParentFormat := False; if Value > 0 then begin Sender.Format.Font.Color := TColors.Green; Sender.Format.Brush.Color := TColorHelper.From(TColors.Lime, 0.1); end else if Value < 0 then begin Sender.Format.Font.Color := TColors.Red; Sender.Format.Brush.Color := TColorHelper.From(TColors.Pink, 0.1); end; end;end;