Cita:
Empezado por Casimiro Notevi
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
public
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;
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;
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