Ver Mensaje Individual
  #120  
Antiguo 08-01-2011
cloayza cloayza is offline
Miembro
 
Registrado: may 2003
Ubicación: San Pedro de la Paz, Chile
Posts: 913
Reputación: 23
cloayza Tiene un aura espectacularcloayza Tiene un aura espectacular
Cita:
Empezado por Casimiro Notevi Ver Mensaje
Nada, acaba alternando colores incorrectamente.
Amigo he implementado el codigo en ejemplo de Chris, y me anda de maravillas...

Te copio el codigo completo de la unidad.

Código Delphi [-]
unit Unit24;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, IBCustomDataSet, IBDatabase, StdCtrls, ComCtrls, Grids, DBGrids;

type
  TForm24 = class(TForm)
    gr1: TDBGrid;
    DS1: TDataSource;
    dtp1: TDateTimePicker;
    lb1: TLabel;
    btn1: TButton;
    DB1: TIBDatabase;
    TR1: TIBTransaction;
    QR1: TIBDataSet;
    QR1CODIGOAPUNTE: TIntegerField;
    QR1CODIGOEMPRESA: TIntegerField;
    QR1EJERCICIO: TSmallintField;
    QR1NUMEROASIENTO: TIntegerField;
    QR1LINEAASIENTO: TIntegerField;
    QR1FECHAASIENTO: TDateField;
    QR1CODIGOCUENTA: TIBStringField;
    QR1CONCEPTO: TIBStringField;
    QR1DEBE: TFloatField;
    QR1HABER: TFloatField;
    QR1FECHACREACION: TDateField;
    QR1HORACREACION: TTimeField;
    procedure btn1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure gr1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure dtp1Exit(Sender: TObject);
  private
    { Private declarations }
{    nValorAnt: Integer;
    FColor, BColor: TColor;
    UltimoValor: Variant;
    BoolSwitch: Boolean;
    GrupoImpar: String;
}
  public
    { Public declarations }
    Sombra:Boolean;
    List:TStrings;
  end;

var
  Form24: TForm24;

implementation

{$R *.dfm}

procedure TForm24.btn1Click(Sender: TObject);
begin
  db1.Open;
  tr1.Active:=True;
  qr1.Close;
  qr1.selectsql.text := 'select * from tbapuntes where codigoempresa=2 and ejercicio=2 and codigoestadoapunte=2 '+
                        'and fechaasiento  between :fechadesde and :fechahasta '+
                        'order by codigoempresa, ejercicio, numeroasiento, lineaasiento';
  qr1.Params[0].AsDate := dtp1.Date;
  qr1.Params[1].AsDate := dtp1.Date;

  if Assigned(List) then
     List.Clear;

  // inicializar los datos del control de grupo
  qr1.Open;
  gr1.SetFocus;
end;

procedure TForm24.dtp1Exit(Sender: TObject);
begin

  btn1.SetFocus;
end;

procedure TForm24.FormClose(Sender: TObject; var Action: TCloseAction);
begin
     DB1.Close;
end;

procedure TForm24.gr1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
   index:Integer;
   fColor:TColor;
begin
      if Not Assigned(List) then
         List:=TStringList.Create;

      with TDBGrid(Sender) do
      begin
         if (gdFocused in State) then
         begin
            Canvas.Font.Color := clWhite;
            Canvas.Brush.Color := clHighlight;
         end
         else
         begin
              Index:=List.IndexOf(DataSource.DataSet.FieldByName('NUMEROASIENTO').AsString);
              if Index=-1 then
              begin
                   if Sombra then fColor:=clYellow  else fColor:=clInfoBk;

                   //fColor:=RGB(Random(205),Random(205),Random(205));

                   index:=List.AddObject(Datasource.Dataset.FieldByName('NUMEROASIENTO').AsString, Pointer(fColor));

                   Sombra := not Sombra;
              end;

              Canvas.Font.Color := clBlack;
              Canvas.Brush.Color := TColor(List.Objects[index]);

              DefaultDrawColumnCell(Rect, DataCol, Column, State);
          end;
      end;
end;

end.

Saludos cordiales
Responder Con Cita