Giving Colors in DBGrid according to criteria

In the Delphi programming, how to color in DBGrid in accordance with the data that we have set, for example, bright green color on the record with data HargaSatuan greater than 250,000? Quite easy, you just add the following code in the event of the DBGrid OnDrawColumncell :

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect:
TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
 if Table1.FieldByName('HargaStuan').AsInteger > 250000      then
 TDBGrid(Sender).Canvas.Brush.Color := clLime;
 TDBGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

No comments:

Post a Comment