Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer;
- Column: TColumn; State: TGridDrawState);
- var
- Field: TField;
- begin
- // store the currently rendered cell's column assigned field (if any) to the local variable to
- // avoid calling quite expensive getter
- Field := Column.Field;
- // if the rendered cell's column has assigned a field and this field's name is 'Clubs', then...
- if Assigned(Field) and SameText(Field.Name, 'Clubs') then
- begin
- if Field.AsString = 'yes' then
- DBGrid1.Canvas.Brush.Color := clRed
- else
- DBGrid1.Canvas.Brush.Color := clYellow;
- end;
- DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
- end;
- // optionally
- procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer;
- Column: TColumn; State: TGridDrawState);
- begin
- // if the rendered cell's column field name is 'Clubs', then... (this test doesn't guarantee there's
- // a matching field in the linked dataset, hence the first option is a bit more safer)
- if SameText(Column.FieldName, 'Clubs') then
- begin
- if Column.Field.AsString = 'yes' then
- DBGrid1.Canvas.Brush.Color := clRed
- else
- DBGrid1.Canvas.Brush.Color := clYellow;
- end;
- DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement