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
Antwort Antwort
wendelin

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

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
Benutzerbild von ATS3788
ATS3788

Registriert seit: 18. Mär 2004
Ort: Kriftel
646 Beiträge
 
Delphi XE Starter
 
#2

AW: Alternierende Farben in TDBGrid

  Alt 28. Dez 2014, 16:23
Danke Wendelin
das schau ich mir mal an.

Ich habe gesehen das man das nun auch mit dem Themes machen kann,
das ist ja echt cool, nur mit dem Haken das man die Bitmaps, Skins nur
kompliziert mit einem externen Grafikprogramm
ändern kann.

Gibt es da ein Programm um die styles.bmp komfortabel zu ändern.

Guten Rutsch

Martin Michael
Martin MIchael
  Mit Zitat antworten Zitat
wendelin

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

AW: Alternierende Farben in TDBGrid

  Alt 2. Jan 2015, 10:36
Hallo Martin,
mit Themes und Skins kenne ich mich überhaupt nicht aus.
Da kann ich Dir also gar nicht helfen.
Eine Frage aber: Was hat das mit alternierenden Farben im DB-Grid zu tun ?

Ein frohes neues Jahr wünscht Dir
Wendelin
Wolfgang
  Mit Zitat antworten Zitat
Benutzerbild von Bernhard Geyer
Bernhard Geyer

Registriert seit: 13. Aug 2002
17.223 Beiträge
 
Delphi 10.4 Sydney
 
#4

AW: Alternierende Farben in TDBGrid

  Alt 2. Jan 2015, 11:04
Gibt es da ein Programm um die styles.bmp komfortabel zu ändern.
Paint.net?

Also ich finde das Konzept relativ einfach. Verglichen mit dem alten Konzept auf Basis der .msstyles-DLLs ist es m. E. primitiv einfach.
Du hat eine große Bitmap und definierst welcher Teil davon jetzt die Buttons, Checkboxen, ... darstellt.
Einem Designer musst du auch nur diese kleine Datei mitgeben wenn du nur die Bilder ändern willst.
Windows Vista - Eine neue Erfahrung in Fehlern.
  Mit Zitat antworten Zitat
Antwort Antwort


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 08:55 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