Recent

Author Topic: [SOLVED] tdbgrid colore entire row  (Read 784 times)

superc

  • New Member
  • *
  • Posts: 25
[SOLVED] tdbgrid colore entire row
« on: October 15, 2019, 11:57:30 am »
Hello,

I'm using a TDBGrid and i want colore an entire row not specific cell:

My code for colore a specific cell is

Code: Pascal  [Select]
  1. procedure TfrmDeclareBatch.DBGrid1PrepareCanvas(sender: TObject;
  2.   DataCol: Integer; Column: TColumn; AState: TGridDrawState);
  3. begin
  4.   if (DataCol = 2) then
  5.   begin
  6.     if Column.Field.AsInteger = 1  then
  7.     begin
  8.        (sender as TDBGrid).Canvas.Brush.Color := clGreen;
  9.     end;
  10.   end;
  11.  
  12. end;
  13.  

Thanks in advance.
« Last Edit: October 15, 2019, 05:26:02 pm by superc »

paweld

  • Full Member
  • ***
  • Posts: 186
Re: tdbgrid colore entire row
« Reply #1 on: October 15, 2019, 01:56:32 pm »
Code: Pascal  [Select]
  1. procedure TfrmDeclareBatch.DBGrid1PrepareCanvas(sender: TObject;
  2.   DataCol: Integer; Column: TColumn; AState: TGridDrawState);
  3. begin
  4.   if Column.Field.AsInteger = 1  then
  5.   begin
  6.      (sender as TDBGrid).Canvas.Brush.Color := clGreen;
  7.   end;
  8. end;
Best regards
paweld

superc

  • New Member
  • *
  • Posts: 25
Re: tdbgrid colore entire row
« Reply #2 on: October 15, 2019, 05:12:10 pm »

Almost ok,

I solved it this way:


Code: Pascal  [Select]
  1.     case ts  of
  2.           TState.ST_DECLARE_BATCH:
  3.           begin
  4.  
  5.             if ((Column.FieldName = 'codA') or
  6.                 (Column.FieldName = 'codB') or
  7.                 (Column.FieldName = 'codC') or
  8.                 (Column.FieldName = 'codE')) then
  9.             begin
  10.               nval := 0;
  11.               nval := mdDistinctArt.FieldByName('codC').AsInteger;
  12.               if (nval >= 1) then
  13.               begin
  14.                 (sender as TDBGrid).Canvas.Brush.Color := TColor($0080FF);
  15.                 (sender as TDBGrid).Canvas.Font.Color := TColor(clWhite);
  16.               end;
  17.  
  18.               if (nval = 0) then
  19.               begin
  20.                 (sender as TDBGrid).Canvas.Brush.Color := TColor($FFBBAA);
  21.                 (sender as TDBGrid).Canvas.Font.Color := TColor(clWhite);
  22.               end;
  23.             end;
  24.  
  25.           end;  
  26.  

jamie

  • Hero Member
  • *****
  • Posts: 2070
Re: [SOLVED] tdbgrid colore entire row
« Reply #3 on: October 16, 2019, 01:23:08 am »
Allow me to show you a trick!

Code: Pascal  [Select]
  1. if String(Column.FieldName+',').Contains('codA,codB,codC,codD,') Then....
  2.  
  3.  
  4.  
Number 1 at blue screen app creations!

superc

  • New Member
  • *
  • Posts: 25
Re: [SOLVED] tdbgrid colore entire row
« Reply #4 on: October 16, 2019, 08:22:43 am »
Allow me to show you a trick!

Code: Pascal  [Select]
  1. if String(Column.FieldName+',').Contains('codA,codB,codC,codD,') Then....
  2.  
  3.  
  4.  

very sexy
 :D