PAGUE 6 MESES
LEVE 12 MESES
GARANTIR DESCONTO

Fórum Dúvida evento DrawColumnCell #367439

30/12/2008

0

Bom dia,

Utilizo o Delphi 6 e no evento DrawColumnCell coloquei um código que muda a cor da célula quando o valor do campo for menor que 70, funciona corretamente só que quando a seleção das linhas é feita de baixo para cima no DBGRID a cor da célula só muda quando a segunda linha é selecionada por exemplo:


de cima para baixo

linha1 valor 80 cor preto
linha2 valor 100 cor preto
linha3 valor 40 ( muda cor para azul ) CORRETO
linha4 valor 200 cor preto


de baixo para cima

linha1 valor 80 cor preto
linha2 valor 100 ( muda cor para azul ) da linha abaixo
linha3 valor 40 cor preto NÃO MUDA A COR (BUG DO COMPONENTE OU DO CÓDIGO )
linha4 valor 200 cor preto

Se abaixo o código:


procedure TfrmLeitura.dbgRegistrosDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin

if rgOpcao.ItemIndex = 0 then
begin

if (LowerCase(Column.Field.FieldName) = ´razao_dicionario´) then
begin
if Column.Field.Value >= 98 then begin
dbgRegistros.Canvas.Font.Color:= clBlue;
dbgRegistros.Canvas.FillRect(Rect);
dbgRegistros.DefaultDrawColumnCell(Rect, DataCol, Column, State);
lblAviso.Font.Color:=clBlue;
lblAviso.Caption:=´Resultado esperado, não é necessário ajuste.´;
end
else
if (Column.Field.Value > 92) and (Column.Field.Value < 98) then
begin
dbgRegistros.Canvas.Font.Color:= clMaroon;
dbgRegistros.Canvas.FillRect(Rect);
dbgRegistros.DefaultDrawColumnCell(Rect, DataCol, Column, State);
lblAviso.Font.Color:=clMaroon;
lblAviso.Caption:=´Resultado aceitável, pode ser ajustado para ganhar performance.´;
end
else
if (Column.Field.Value > 86) and (Column.Field.Value < 92) then
begin
dbgRegistros.Canvas.Font.Color:= clYellow;
dbgRegistros.Canvas.FillRect(Rect);
dbgRegistros.DefaultDrawColumnCell(Rect, DataCol, Column, State);
lblAviso.Font.Color:=clYellow;
lblAviso.Caption:=´Resultado crítico, altamente recomendável o ajuste.´;
end
else
begin
dbgRegistros.Canvas.Font.Color:= clRed;
dbgRegistros.Canvas.FillRect(Rect);
dbgRegistros.DefaultDrawColumnCell(Rect, DataCol, Column, State);
lblAviso.Font.Color:=clRed;
lblAviso.Caption:=´Resultado crítico, o ajuste de ser executado com urgência.´;
end;
end;
end;


if rgOpcao.ItemIndex = 1 then
begin

if (LowerCase(Column.Field.FieldName) = ´pct_memory_sorts´) then
begin
if Column.Field.Value >= 98 then begin
dbgRegistros.Canvas.Font.Color:= clBlue;
dbgRegistros.Canvas.FillRect(Rect);
dbgRegistros.DefaultDrawColumnCell(Rect, DataCol, Column, State);
lblAviso.Font.Color:=clBlue;
lblAviso.Caption:=´Resultado esperado, não é necessário ajuste.´;
end
else
if (Column.Field.Value > 95) and (Column.Field.Value < 98) then
begin
dbgRegistros.Canvas.Font.Color:= clMaroon;
dbgRegistros.Canvas.FillRect(Rect);
dbgRegistros.DefaultDrawColumnCell(Rect, DataCol, Column, State);
lblAviso.Font.Color:=clMaroon;
lblAviso.Caption:=´Resultado aceitável, pode ser ajustado para ganhar performance.´;
end
else
if (Column.Field.Value > 90) and (Column.Field.Value < 94) then
begin
dbgRegistros.Canvas.Font.Color:= clYellow;
dbgRegistros.Canvas.FillRect(Rect);
dbgRegistros.DefaultDrawColumnCell(Rect, DataCol, Column, State);
lblAviso.Font.Color:=clYellow;
lblAviso.Caption:=´Resultado crítico, altamente recomendável o ajuste.´;
end
else
begin
dbgRegistros.Canvas.Font.Color:= clRed;
dbgRegistros.Canvas.FillRect(Rect);
dbgRegistros.DefaultDrawColumnCell(Rect, DataCol, Column, State);
lblAviso.Font.Color:=clRed;
lblAviso.Caption:=´Resultado crítico, o ajuste de ser executado com urgência.´;
end;
end;
end;


if rgOpcao.ItemIndex = 2 then
begin

if (LowerCase(Column.Field.FieldName) = ´acerto_buffer´) then begin
if Column.Field.Value >= 98 then begin
dbgRegistros.Canvas.Font.Color:= clBlue;
dbgRegistros.Canvas.FillRect(Rect);
dbgRegistros.DefaultDrawColumnCell(Rect, DataCol, Column, State);
lblAviso.Font.Color:=clBlue;
lblAviso.Caption:=´Resultado esperado, não é necessário ajuste.´;
end
else
if (Column.Field.Value > 95) and (Column.Field.Value < 98) then
begin
dbgRegistros.Canvas.Font.Color:= clMaroon;
dbgRegistros.Canvas.FillRect(Rect);
dbgRegistros.DefaultDrawColumnCell(Rect, DataCol, Column, State);
lblAviso.Font.Color:=clMaroon;
lblAviso.Caption:=´Resultado aceitável, pode ser ajustado para ganhar performance.´;
end
else
if (Column.Field.Value > 90) and (Column.Field.Value < 94) then
begin
dbgRegistros.Canvas.Font.Color:= clYellow;
dbgRegistros.Canvas.FillRect(Rect);
dbgRegistros.DefaultDrawColumnCell(Rect, DataCol, Column, State);
lblAviso.Font.Color:=clYellow;
lblAviso.Caption:=´Resultado crítico, altamente recomendável o ajuste.´;
end
else
begin
dbgRegistros.Canvas.Font.Color:= clRed;
dbgRegistros.Canvas.FillRect(Rect);
dbgRegistros.DefaultDrawColumnCell(Rect, DataCol, Column, State);
lblAviso.Font.Color:=clRed;
lblAviso.Caption:=´Resultado crítico, o ajuste de ser executado com urgência.´;
end;
end;
end;


if rgOpcao.ItemIndex = 3 then
begin

if (LowerCase(Column.Field.FieldName) = ´percentual_utilizado´) then
begin
if Column.Field.Value <= 70 then begin
dbgRegistros.Canvas.Font.Color:= clBlue;
dbgRegistros.Canvas.FillRect(Rect);
dbgRegistros.DefaultDrawColumnCell(Rect, DataCol, Column, State);
lblAviso.Font.Color:=clBlue;
lblAviso.Caption:=´Resultado esperado, não é necessário ajuste.´;
end
else
if (Column.Field.Value > 70) and (Column.Field.Value <= 80) then
begin
dbgRegistros.Canvas.Font.Color:= clMaroon;
dbgRegistros.Canvas.FillRect(Rect);
dbgRegistros.DefaultDrawColumnCell(Rect, DataCol, Column, State);
lblAviso.Font.Color:=clMaroon;
lblAviso.Caption:=´Resultado aceitável, pode ser ajustado para ganhar performance.´;
end
else
if (Column.Field.Value > 80) and (Column.Field.Value <= 90) then
begin
dbgRegistros.Canvas.Font.Color:= clYellow;
dbgRegistros.Canvas.FillRect(Rect);
dbgRegistros.DefaultDrawColumnCell(Rect, DataCol, Column, State);
lblAviso.Font.Color:=clYellow;
lblAviso.Caption:=´Resultado crítico, altamente recomendável o ajuste.´;
end
else
begin
dbgRegistros.Canvas.Font.Color:= clRed;
dbgRegistros.Canvas.FillRect(Rect);
dbgRegistros.DefaultDrawColumnCell(Rect, DataCol, Column, State);
lblAviso.Font.Color:=clRed;
lblAviso.Caption:=´Resultado crítico, o ajuste de ser executado com urgência.´;
end;
end;
end;

end;




Se alguém tiver uma idéia ou dica agradeço.

Airton


Airoosp

Airoosp

Responder

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar