Una pequena optimizacion de codigo que propuse anteriormente.
Código Delphi
[-]
Sombra:Boolean;
List:TStrings;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.DBGrid1DrawColumnCell(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('ASIENTO').AsString);
if Index=-1 then
begin
if Sombra then fColor:=clYellow else fColor:=clInfoBk;
index:=List.AddObject(Datasource.Dataset.FieldByName('ASIENTO').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;
Saludos cordiales