Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Procurei na net e achei vários exemplos... tento todos e não consigo colorir as células do meu grid que tenham conteúdo TRUE.
Alguém tem algo que efetivamente já usou e funcionou para me passar? O que será que estou fazendo errado, segue o meu código
procedure TfrmPrincipal.gridGeneralDrawDataCell(Sender: TObject;
const Rect: TRect; Field: TField; State: TGridDrawState);
begin
if gridGeneral.DataSource.DataSet.FieldByName('UnderApproval').asBoolean = true then
gridGeneral.Canvas.Brush.Color:= clRed;
gridGeneral.Canvas.FillRect(Rect);
gridGeneral.DefaultDrawDataCell(Rect,gridGeneral.columns[0].field,State);
end;
No aguardo, valeu!>
Tenta essa:
procedure TfrmPrincipal.gridGeneralDrawDataCell(Sender: TObject;
const Rect: TRect; Field: TField; State: TGridDrawState);
begin
if Table1.FieldByName('UnderApproval').asBoolean = True then
DBGrid1.Canvas.Brush.Color := clRed
else
DBGrid1.Canvas.Brush.Color := clGreen;
DBGrid1.Canvas.FillRect(Rect);
DBGrid1.DefaultDrawDataCell(Rect,Field,State);
end;
Não deu certo, com esse código eu consegui um grid totalmente em branco!
Modera... pode colocar [RESOLVIDO] rs
procedure TfrmPrincipal.gridGeneralDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
If (Column.Index = 5) and Not (gdFocused in State) Then
if gridGeneral.DataSource.DataSet.FieldByName('correctAnswer').asString = 'a' then
Begin
gridGeneral.Canvas.Brush.Color := clYellow;
gridGeneral.Canvas.font.Color := clBlack;
End;
If (Column.Index = 6) and Not (gdFocused in State) Then
if gridGeneral.DataSource.DataSet.FieldByName('correctAnswer').asString = 'b' then
Begin
gridGeneral.Canvas.Brush.Color := clYellow;
gridGeneral.Canvas.font.Color := clBlack;
End;
If (Column.Index = 7) and Not (gdFocused in State) Then
if gridGeneral.DataSource.DataSet.FieldByName('correctAnswer').asString = 'c' then
Begin
gridGeneral.Canvas.Brush.Color := clYellow;
gridGeneral.Canvas.font.Color := clBlack;
End;
gridGeneral.DefaultDrawColumnCell(Rect, DataCol, Column, State) ;
end;
Valeu!Realmente colega errei nessa parte do código:
DBGrid1.Canvas.FillRect(Rect);
DBGrid1.DefaultDrawDataCell(Rect,Field,State);
Ele tem q ficar fora do bloco IF, ELSE, senão não vai funcionar mesmo.
Tenta essa:
begin
if Table1.FieldByName('UnderApproval').asBoolean = True then
DBGrid1.Canvas.Brush.Color := clRed
else