AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Datenbanken Delphi Alternierende Farben in TDBGrid
Thema durchsuchen
Ansicht
Themen-Optionen

Alternierende Farben in TDBGrid

Ein Thema von ATS3788 · begonnen am 23. Dez 2014 · letzter Beitrag vom 2. Jan 2015
 
wendelin

Registriert seit: 29. Dez 2010
Ort: Nürnberg
126 Beiträge
 
Delphi 7 Enterprise
 
#3

AW: Alternierende Farben in TDBGrid

  Alt 23. Dez 2014, 11:37
Hallo,
Hier mein Source-Code:
Delphi-Quellcode:
unit QRNeu;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, QuickRpt, QRCtrls, DBGrids, nuetzlFunctions1, QRExport;

type
  TGridReport = class(TForm)
    GridRep : TQuickRep;
    DetailBand1: TQRBand;
    QRTextFilter1: TQRTextFilter;
    QRCSVFilter1: TQRCSVFilter;
    QRHTMLFilter1: TQRHTMLFilter;
    procedure GridRepPreview(Grid : TDBGrid);
    procedure DetailBand1BeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }

  end;

var
  GridReport: TGridReport;

implementation

uses DataMod2, DataMod1;

{$R *.dfm}

(******************************************************************************)
 procedure TGridReport.GridRepPreview(Grid : TDBGrid);
(******************************************************************************)
var
  i, CurrentLeft, CurrentTop : integer;
  MySQLString : STRING;

begin
  GridRep.Dataset:=Grid.DataSource.DataSet;

  if not GridRep.Bands.HasColumnHeader then // NEU
    GridRep.Bands.HasColumnHeader:=true;

  if not GridRep.Bands.HasDetail then // wird normalerweise NICHT
    GridRep.Bands.HasDetail:=true; // benötigt !!

  if not GridRep.Bands.HasPageFooter then // NEU
    GridRep.Bands.HasPageFooter := TRUE;

  MySQLString := DataModule2.IBQ1.Text; // NEU

  GridRep.Bands.ColumnHeaderBand.Height:= Abs(Grid.TitleFont.Height) + 10;
  GridRep.Bands.DetailBand.Height := Abs(Grid.Font.Height) + 10;
  GridRep.Bands.PageFooterBand.Height := Abs(Grid.Font.Height) + 10;

  CurrentLeft := 12;
  CurrentTop := 4; // 6

  Grid.DataSource.DataSet.DisableControls; // don't flicker !!

  try
    for i:=0 to Grid.FieldCount - 1 do
    begin
      if (CurrentLeft + Canvas.TextWidth(Grid.Columns[i].Title.Caption)) >
         (GridRep.Bands.ColumnHeaderBand.Width) then
      begin
        CurrentLeft := 12;
        CurrentTop := CurrentTop + Canvas.TextHeight('A') + 6;
        GridRep.Bands.ColumnHeaderBand.Height :=
        GridRep.Bands.ColumnHeaderBand.Height +
          (Canvas.TextHeight('A') + 10);
        GridRep.Bands.DetailBand.Height :=
        GridRep.Bands.DetailBand.Height +
          (Canvas.TextHeight('A') + 10);
      end;

      {Create Header with QRLabels}
      with TQRLabel.Create(GridRep.Bands.ColumnHeaderBand) do
      begin
        Parent := GridRep.Bands.ColumnHeaderBand;
        Color := GridRep.Bands.ColumnHeaderBand.Color;
        Left := CurrentLeft;
        Top := CurrentTop - 10; // korr. !
        Caption := Grid.Columns[i].Title.Caption;
        Font.Style := [fsBold,fsUnderline];
      end;

      {Create Detail with QRDBText}
      with TQRDBText.Create(GridRep.Bands.DetailBand) do
      begin
        Parent := GridRep.Bands.DetailBand;
        Color := GridRep.Bands.DetailBand.Color;
        Transparent := TRUE; // NEU für Farbwechsel des DetailBandes
        Left := CurrentLeft;
        Top := CurrentTop;
        Alignment := taLeftJustify; // NEU / Alt -> Grid.Columns[i].Alignment;
        AutoSize := FALSE;
        AutoStretch := FALSE; // korr. !
        WordWrap := FALSE; // NEU
        Width := Grid.Columns[i].Width;
        Dataset := GridRep.Dataset;
        DataField := Grid.Fields[i].FieldName;
        CurrentLeft := CurrentLeft + (Grid.Columns[i].Width) + 15;
      end;
    end;

    {Create SysData / Datum-Zeit}
    with TQRSysData.Create(GridRep.Bands.PageFooterBand) do
    begin
      Parent := GridRep.Bands.PageFooterBand;
      Color := clWhite;
      Left := 10;
      Top := CurrentTop;
      Alignment := taLeftJustify;
      Data := qrsDateTime;
      Font.Charset := DEFAULT_CHARSET;
      Font.Color := clWindowText;
      Font.Height := -13;
      Font.Name := 'Arial';
      Font.Style := [fsBold];
    end;
    
    {Create Label / SQL-Statement}
    with TQRLabel.Create(GridRep.Bands.PageFooterBand) do
    begin
      Parent := GridRep.Bands.PageFooterBand;
      Color := clWhite;
      Left := 170;
      Top := CurrentTop;
      Alignment := taLeftJustify;
      Caption := MySQLString; // akt. SQLSTRING
      Font.Charset := DEFAULT_CHARSET;
      Font.Color := clWindowText;
      Font.Height := -13;
      Font.Size := 6;
      Font.Name := 'Small Fonts';
      Font.Style := [fsBold]; // [fsBold,fsUnderline];
    end;

    {Create Label / Seite :}
    with TQRLabel.Create(GridRep.Bands.PageFooterBand) do
    begin
      Parent := GridRep.Bands.PageFooterBand;
      Color := clWhite;
      Left := 948;
      Top := CurrentTop;
      Alignment := taLeftJustify;
      Caption := 'SEITE :';
      Font.Charset := DEFAULT_CHARSET;
      Font.Color := clWindowText;
      Font.Height := -13;
      Font.Name := 'Arial';
      Font.Style := [fsBold];
    end;

    {Create SysData / Seitennummer}
    with TQRSysData.Create(GridRep.Bands.PageFooterBand) do
    begin
      Parent := GridRep.Bands.PageFooterBand;
      Color := clWhite;
      Left := 1024;
      Top := CurrentTop;
      Alignment := taLeftJustify;
      Data := qrsPageNumber;
      Font.Charset := DEFAULT_CHARSET;
      Font.Color := clWindowText;
      Font.Height := -13;
      Font.Name := 'Arial';
      Font.Style := [fsBold];
    end;

                                 {After all, call the QuickRep preview method}
    GridRep.Preview; {or PreviewModal if you prefer}

  finally
    // After all, FREE it NEU!
    GridRep.Bands.ColumnHeaderBand.Free; // wichtig sonst eListError
    GridRep.Bands.DetailBand.DestroyComponents; // SEHR WICHTIG !!
    GridRep.Bands.PageHeaderBand.Free; // wichtig sonst eListError
    GridRep.Bands.PageFooterBand.Free; // sonst Darstellungsfehler
    with Grid.DataSource.DataSet do
    begin
      EnableControls;
    end;
  end;
end;

(******************************************************************************)
 procedure TGridReport.DetailBand1BeforePrint(Sender: TQRCustomBand;
(******************************************************************************)
var PrintBand: Boolean);
begin
  If GridReport.DetailBand1.Color = clMoneyGreen THEN
     GridReport.DetailBand1.Color := clWhite ELSE
     GridReport.DetailBand1.Color := clMoneyGreen;
end;

end.
Ich weiss allerdings nicht ob sich QuickReport mit Deinem Delphi XE Verträgt!
Wenn nicht schreib mir, ich werde dann versuchen Dein Problem mit dem DB-Grid zu lösen.

Frohe Weihnachten
Wendelin
Angehängte Grafiken
Dateityp: jpg BeispQuickRep.JPG (180,6 KB, 31x aufgerufen)
Wolfgang
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:34 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz