Ver Mensaje Individual
  #102  
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
Revisando todos los post se me ocurrio hacer lo siguiente...

Me recorde que cuando en la grilla uno realiza seleccion de registros internamente se utiliza un TList para almacenar los bookmark de los registros seleccionados, debido a eso pense en utilizar un TStrings para almacenar la informacion que se requiere por cada registro.

Este es el resultado, tome el codigo del amigo duilioisola y le hice algunos cambios...

Código Delphi [-]
 public
    { Public declarations }
    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
//Busco el Asiento en el List            
Index:=List.IndexOf(DataSource.DataSet.FieldByName('ASIENTO').AsString);
//Obtengo el valor boolean para realizar la pregunta...
            if Boolean(List.Objects[index]) then
            begin
               Canvas.Font.Color := clBlack;
               Canvas.Brush.Color := clYellow;
            end
            else
            begin
               Canvas.Font.Color := clBlack;
               Canvas.Brush.Color := clInfoBk;
            end;
         end;
         DefaultDrawColumnCell(Rect, DataCol, Column, State);
      end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
     List:=TStringList.Create; //Creo el list que almacenara los datos de cada rfegistro...
     
     Table1.Active:=True;
end;

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

procedure TForm1.Table1CalcFields(DataSet: TDataSet);
var
   Index:Integer;
begin
      //Verifico si el Asiento ya esta en la List...
     Index:=List.IndexOf(DataSet.FieldByName('ASIENTO').AsString);
     if Index=-1 then
     begin
          //AL no encontrase en List lo agrego con el valor booleano de sombra...
          List.AddObject(DataSet.FieldByName('ASIENTO').AsString, Pointer(Sombra) );
          Sombra := not Sombra;
     end;
end;

Por supuesto faltan las validaciones...
Saludos cordiales

Última edición por cloayza fecha: 07-01-2011 a las 21:04:04.
Responder Con Cita