Line 21: | Line 21: | ||
==Examples== |
==Examples== |
||
− | + | <pre>procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); |
|
+ | var |
||
− | |||
+ | veri: AnsiString; |
||
− | DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);<br /><br />// Burada özel boyama işlemleri bitmiştir. Artık kendi özelimize girebiliriz.<br />if not (Column.Field.DataType = null) then<br />begin<br />if TDBGrid(Sender).Canvas.TextWidth(Column.Field.asString) > (Rect.Right-Rect.Left) then<br />begin<br />// Canvas varsayılan font tipine göre, Filed içindeki text veri, eğer<br />// DataCell yani hücrenin eninden büyükse. (demek ki devamında örtülü kısım var)<br />// Bu durumda örtülü olmayan kısım olana kadar sondan ve fazladan 3 tane fazla kırpıp<br />// bu sonradan kırpılan fazlalık kısım yerine ... koyucaz.. nasıl mı ?<br />Veri := Column.Field.asString;<br />while TDBGrid(Sender).Canvas.TextWidth(Veri) > (Rect.Right-Rect.Left) do<br />Delete(Veri, Length(Veri), 1); // Sondan geri doğru kırpıyoruz..<br />For i := 1 to 3 do Delete(Veri, Length(Veri), 1); // 3 tane fazla kırptık...<br />Veri := Veri + '...';<br />TDBGrid(Sender).Canvas.FillRect(Rect); // Önce renk doldur..<br />TDBGrid(Sender).Canvas.TextOut( Rect.Left+1, Rect.Top+1, Veri );<br />end;<br />end;<br />end; |
||
+ | i: Integer; |
||
+ | begin |
||
+ | if (gdSelected in state) then |
||
+ | begin |
||
+ | DBGrid1.Canvas.Brush.Color := $00A00000; |
||
+ | DbGrid1.Canvas.Font.Color := clWhite; |
||
+ | end |
||
+ | else |
||
+ | begin |
||
+ | if (DBGrid1.DataSource.DataSet.RecNo mod 2) =0 then |
||
+ | DBGrid1.Canvas.Brush.Color := clGray |
||
+ | else |
||
+ | DBGrid1.Canvas.Brush.Color := clTeal; |
||
+ | end; |
||
+ | DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); |
||
+ | if not (Column.Field.DataType = null) then |
||
+ | begin |
||
+ | if TDBGrid(Sender).Canvas.TextWidth(Column.Field.asString) > (Rect.Right-Rect.Left) then |
||
+ | begin |
||
+ | veri := Column.Field.asString; |
||
+ | while TDBGrid(Sender).Canvas.TextWidth(Veri) > (Rect.Right-Rect.Left) do |
||
+ | delete(Veri, Length(Veri), 1); |
||
+ | for i := 1 to 3 do |
||
+ | begin |
||
+ | delete(Veri, Length(Veri), 1); |
||
+ | end; |
||
+ | veri := veri + '...'; |
||
+ | TDBGrid(Sender).Canvas.FillRect(Rect); |
||
+ | TDBGrid(Sender).Canvas.TextOut( Rect.Left+1, Rect.Top+1, Veri ); |
||
+ | end; |
||
+ | end; |
||
+ | end; |
||
+ | </pre> |
||
==See Also== |
==See Also== |
Latest revision as of 08:02, 15 November 2011
This page is intended as a supplement to the official documentation on Delphi programming. CodeGear is in the process of putting the Delphi documentation on the Web. Once they have done so, this page will link to the relevant page in the official documentation.
see the VCL Documentation Guidelines for an overview on doc pages
Unit[]
Hierarchy[]
System.TObject < Classes.TPersistent < Classes.TComponent < Controls.TControl < Controls.TWinControl < Controls.TCustomControl < Grids.TCustomGrid < DBGrids.TCustomDBGrid
Description[]
(Please provide a description in your own words. It is illegal to use the wording from the Delphi Help.)
Technical Comments[]
(Known issues / Documentation clarifications / Things to be aware of)
Examples[]
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var veri: AnsiString; i: Integer; begin if (gdSelected in state) then begin DBGrid1.Canvas.Brush.Color := $00A00000; DbGrid1.Canvas.Font.Color := clWhite; end else begin if (DBGrid1.DataSource.DataSet.RecNo mod 2) =0 then DBGrid1.Canvas.Brush.Color := clGray else DBGrid1.Canvas.Brush.Color := clTeal; end; DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State); if not (Column.Field.DataType = null) then begin if TDBGrid(Sender).Canvas.TextWidth(Column.Field.asString) > (Rect.Right-Rect.Left) then begin veri := Column.Field.asString; while TDBGrid(Sender).Canvas.TextWidth(Veri) > (Rect.Right-Rect.Left) do delete(Veri, Length(Veri), 1); for i := 1 to 3 do begin delete(Veri, Length(Veri), 1); end; veri := veri + '...'; TDBGrid(Sender).Canvas.FillRect(Rect); TDBGrid(Sender).Canvas.TextOut( Rect.Left+1, Rect.Top+1, Veri ); end; end; end;
See Also[]
(Please provide links to items specifically related to this item.)
User Comments/Tips[]
(Please leave your name with your comment.)