Ver Mensaje Individual
  #104  
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
Aqui incorporando muchos colores...
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;
begin
      with TDBGrid(Sender) do
      begin
         if (gdFocused in State) then //Si tiene el foco
         begin
            Canvas.Font.Color := clWhite;
            Canvas.Brush.Color := clHighlight;
         end
         else
         begin
            {Sombra puede ser 1 o 2. Si está a 0 no esta establecido}
            Index:=List.IndexOf(DataSource.DataSet.FieldByName('ASIENTO').AsString);

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

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

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
     List:=TStringList.Create;
     Table1.Active:=True;
end;

procedure TForm1.Table1AfterOpen(DataSet: TDataSet);
begin
   Sombra := true;
end;

procedure TForm1.Table1CalcFields(DataSet: TDataSet);
var
   Index:Integer;
   fColor:TColor;
begin
     Index:=List.IndexOf(DataSet.FieldByName('ASIENTO').AsString);
     if Index=-1 then
     begin
          fColor:=RGB(Random(205),Random(205),Random(205));
          List.AddObject(DataSet.FieldByName('ASIENTO').AsString, Pointer(fColor)); //Sombra) );
          Sombra := not Sombra;
     end;
end;
Responder Con Cita