Ver Mensaje Individual
  #2  
Antiguo 16-10-2013
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola rodrinig.

Crea una nueva aplicación, poné un TClientDataSet, un TDataSource, un TTimer un TDBGrid y en tiempo de diseño hace lo siguiente:
  • Doble click sobre el TClientDataSet
  • Click botón derecho -> Click sobre "New Field..."
  • Name: OR_TIPO, Type: Integer
  • Click sobre botón OK.

Luego proba este ejemplo:
Código Delphi [-]
...
implementation

const
  MAX = 200;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  Timer1.Enabled := False;
  Randomize;
  with ClientDataSet1 do
  begin
    CreateDataSet;
    Open;
    for i:= 1 to MAX do
    begin
      Append;
      FieldByName('OR_TIPO').AsInteger := Random(5)+1;
      Post;
    end;
    First;
  end;
  Timer1.Interval := 3000;
  Timer1.Enabled  := True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  i: Integer;
begin
  Timer1.Enabled := False;
  with ClientDataSet1 do
  begin
    DisableControls;
    try
      First;
      for i:= 1 to MAX do
      begin
        Edit;
        FieldByName('OR_TIPO').AsInteger := Random(5)+1;
        Next;
      end;
      First;
    finally
      EnableControls;
    end;
  end;
  Timer1.Enabled := True;
end;

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
  C : TColor;
begin
  with Sender as TDBGrid do
  begin
    case ClientDataSet1.FieldByName('OR_TIPO').AsInteger of
      1: C:= clLime;
      2: C:= clYellow;
      3: C:= clMoneyGreen;
      4: C:= clRed;
      5: C:= clAqua;
    end;
    Canvas.Brush.Color := C;
    DefaultDrawColumnCell(Rect, DataCol, Column, State);
  end;
end;
...

Saludos

Edito: Aunque es obvio, me olvidé de mencionar que asocies el DBgrid al DataSource y este al ClientDataSet para poder visualizar el resultado.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 16-10-2013 a las 22:16:36. Razón: Aclaración
Responder Con Cita