Ver Mensaje Individual
  #11  
Antiguo 07-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
Una pequena optimizacion de codigo que propuse anteriormente.

Código Delphi [-]
 Sombra:Boolean;
    List:TStrings;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ESTE ES EL CODIGO QUE SE REQUIERE...}
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;
{Para usar multicolores aleatorios descomentar esta linea...}
                   //fColor:=RGB(Random(205),Random(205),Random(205));

                   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
Responder Con Cita