Problema com a Cor do DBGrid

Delphi

21/10/2004

Olá pessoal estou usando o seguinte codigo pra ´colorir´ meu DBGrid:
var
 MediaCampo: Real;
begin
 if IBDataSet1.FieldByName(´MEDIA_FINAL´).AsString <> ´´ then
  MediaCampo := IBDataSet1.FieldByName(´MEDIA_FINAL´).AsFloat
 else
  MediaCampo := 0;
 if Odd(IBDataSet1.RecNo) then
 begin
  if Column.FieldName = ´MEDIA_FINAL´ then
  begin
   case ComboBox1.ItemIndex of
    0: begin
      if MediaCampo < 60 then
       DBGrid1.Columns[9].Font.Color := clRed
      else
       DBGrid1.Canvas.Font.Color := clBlack;
     end;
    1: begin
      if MediaCampo < 60 then
       DBGrid1.Columns[9].Font.Color := clRed
      else
       DBGrid1.Canvas.Font.Color := clBlack;
     end;
    2: begin
      if MediaCampo < 60 then
       DBGrid1.Columns[9].Font.Color := clRed
      else
       DBGrid1.Canvas.Font.Color := clBlack;
     end;
    3: begin
      if MediaCampo < 60 then
       DBGrid1.Columns[9].Font.Color := clRed
      else
       DBGrid1.Canvas.Font.Color := clBlack;
     end;
   end;
  end;
  DBGrid1.Canvas.Brush.Color := $00F0FFFF;
 end
 else
 begin
  if Column.FieldName = ´MEDIA_FINAL´ then
  begin
   case ComboBox1.ItemIndex of
    0: begin
      if MediaCampo < 60 then
       DBGrid1.Columns[9].Font.Color := clRed
      else
       DBGrid1.Canvas.Font.Color := clBlack;
     end;
    1: begin
      if MediaCampo < 60 then
       DBGrid1.Columns[9].Font.Color := clRed
      else
       DBGrid1.Canvas.Font.Color := clBlack;
     end;
    2: begin
      if MediaCampo < 60 then
       DBGrid1.Columns[9].Font.Color := clRed
      else
       DBGrid1.Canvas.Font.Color := clBlack;
     end;
    3: begin
      if MediaCampo < 60 then
       DBGrid1.Columns[9].Font.Color := clRed
      else
       DBGrid1.Canvas.Font.Color := clBlack;
     end;
   end;
  end;
  DBGrid1.Canvas.Brush.Color := $00F0FFFF;
  DBGrid1.Canvas.Brush.Color := clWhite;
 end;
 DBGrid1.Canvas.FillRect(Rect);
 DBGrid1.Canvas.TextOut(Rect.Left + 2, Rect.Top, Column.Field.ASString);


o problema, eh que quando o fundo nao estao em branco, quando eu seleciono ele a fonte fica em branco, e pelo fundo ser claro, nao aparece....

como eu arrumo isso?

desdej agradeco


Titanius

Titanius

Curtidas 0

Respostas

Motta

Motta

21/10/2004

exemplo de como eu faço


 
procedure TfrmFicha.dbgDrawColumnCell(Sender: TObject;
   const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);

  procedure MudaCor (Fundo,Fonte: TColor);
  begin
    with dbg.Canvas do
    begin
      Brush.Color := Fundo;
      Font.Color  := Fonte;
      FillRect(Rect);
      TextOut(Rect.Left,Rect.Top,Column.Field.DisplayText);
    end;
  end;

begin
  inherited;
  With dbg..Canvas do
  begin
    if ... then
      MudaCor(clInfoBk,ClRed);
    if ....IsNull then
      MudaCor(clInfoBk,clGreen);
    //Não esqueça de colocar a opção dgRowSelect como True na options do DBGrid.
    // Inverte a cor da celula focada
    if gdFocused in State then
      Mudacor(Font.Color,Brush.Color);  {<<==}
  end;
end; 
  



GOSTEI 0
POSTAR