Advertisement
TLama

Untitled

Nov 19th, 2014
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.32 KB | None | 0 0
  1. procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer;
  2.   Column: TColumn; State: TGridDrawState);
  3. var
  4.   Field: TField;
  5. begin
  6.   // store the currently rendered cell's column assigned field (if any) to the local variable to
  7.   // avoid calling quite expensive getter
  8.   Field := Column.Field;
  9.   // if the rendered cell's column has assigned a field and this field's name is 'Clubs', then...
  10.   if Assigned(Field) and SameText(Field.Name, 'Clubs') then
  11.   begin
  12.     if Field.AsString = 'yes' then
  13.       DBGrid1.Canvas.Brush.Color := clRed
  14.     else
  15.       DBGrid1.Canvas.Brush.Color := clYellow;
  16.   end;
  17.   DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
  18. end;
  19.  
  20. // optionally
  21. procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer;
  22.   Column: TColumn; State: TGridDrawState);
  23. begin
  24.   // if the rendered cell's column field name is 'Clubs', then... (this test doesn't guarantee there's
  25.   // a matching field in the linked dataset, hence the first option is a bit more safer)
  26.   if SameText(Column.FieldName, 'Clubs') then
  27.   begin
  28.     if Column.Field.AsString = 'yes' then
  29.       DBGrid1.Canvas.Brush.Color := clRed
  30.     else
  31.       DBGrid1.Canvas.Brush.Color := clYellow;
  32.   end;
  33.   DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
  34. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement