home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / full / delphi / DELPHI16 / TECHINFO / DELPHI / TIS / TI2815.FX < prev    next >
Encoding:
Text File  |  1995-08-24  |  1.2 KB  |  61 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.   PRODUCT  :  Delphi                                 NUMBER  :  2815
  8.   VERSION  :  All
  9.        OS  :  Windows
  10.      DATE  :  July 14, 1995                            PAGE  :  1/1
  11.  
  12.     TITLE  :  How to handle text drawing in a TDBGrid
  13.  
  14.  
  15.  
  16.  
  17. The following method can be used as the event handler for a 
  18. TDBGrid.OnDrawDataCell event.  This method demonstrates how
  19. to paint the text in one column a different color than the
  20. rest of the text in the grid.
  21.  
  22. procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  23.   Field: TField; State: TGridDrawState);
  24. { NOTE: DefaultDrawing propery of Grid(s) must be set to False }
  25. begin
  26.   { if field name is "NAME" }
  27.   if Field.FieldName = 'NAME' then       
  28.     { change font color to red }
  29.     (Sender as TDBGrid).Canvas.Font.Color := clRed;  
  30.   { draw text in the grid }
  31.   (Sender as TDBGrid).Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2,
  32.                                       Field.AsString);
  33. end;
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. DISCLAIMER: You have the right to use this technical information
  58. subject to the terms of the No-Nonsense License Statement that
  59. you received with the Borland product to which this information
  60. pertains.
  61.