View Issue Details

IDProjectCategoryView StatusLast Update
0028986LazarusLCLpublic2017-07-05 19:14
ReporterUliAssigned Towp 
Status resolvedResolutionno change required 
Platformi386-win32/x86-win64OSWindowsOS Version7 Prof.
Product Version1.4.4Product BuildSVN 49931 
Target VersionFixed in Version1.3 (SVN) 
Summary0028986: If the DBGRID DefaultDrawing property set to FALSE the properties of column titles AND Cells are lost
DescriptionIn addition to issue 24039 also the properties of the data-cells are lost.

TagsNo tags attached.
Fixed in Revision46408
Attached Files


related to 0024039 resolvedJesus Reyes TDBGrid Column Titles lost properties 


Jesus Reyes

2016-04-26 01:44

developer   ~0092227

This problem should have been fixed in r46408 if not please reopen


2017-06-10 17:20

reporter   ~0100996

Sorry, after a long time I test it again (Laz 1.6.4, FPC 3.0.2) and there is the same wrong behavior


2017-06-23 22:27


DefaultDraw_TRUE.jpg (103,930 bytes)
DefaultDraw_TRUE.jpg (103,930 bytes)


2017-06-23 22:28


DefaultDraw_FALSE.jpg (81,675 bytes)
DefaultDraw_FALSE.jpg (81,675 bytes)


2017-06-23 22:28


OnDrawColumnCell.jpg (21,466 bytes)
OnDrawColumnCell.jpg (21,466 bytes)


2017-06-23 22:32

reporter   ~0101312

Database: SQLite3


2017-06-24 00:59

developer   ~0101314

Last edited: 2017-06-25 19:35

View 2 revisions

I don't know, is this really an issue? If you turn off DefaultDrawing then you tell the grid that you want to draw everything by yourself, i.e. you want to draw your own background, your own fonts, etc. I even wonder why texts are displayed at all.

I tested with Delphi Berlin: it does not draw any cell texts any more if the grid's DefaultDrawing is turned off.


2017-07-01 22:28



2017-07-01 22:29



2017-07-01 23:14

reporter (74,647 bytes)


2017-07-01 23:18

reporter   ~0101418

I build a test application with the same database under Delphi 10.2, and the same OnDrawColumnCell - procedure...the behavior is different to Lazarus!

Requirement: UniDac 7.0.2 (Trial:


2017-07-02 00:25

developer   ~0101419

Last edited: 2017-07-02 01:13

View 2 revisions

I don't know what's wrong with this demo, or maybe it is due to the fact that I only have Delphi 10.1 Berlin Starter, or it is a restriction of the UniDAC Trial, but the window with the DBGrid is inoperable.

But if I turn DefaultDrawing off, open connection and query, and click into the grid the cell content goes away, as well as the green cell background. That's how it should be because "no DefaultDrawing" means that all drawing should be executed in events.

Look at the attached screenshot. Note that the dataset is active because the gridlines are displayed. (The grid would should display only a single row if the dataset were not active).

So, Delphi 10.1 is behaving almost like Lazarus - the only difference is that Lazarus seems to display the cell texts, which is a bug in my eyes.


2017-07-02 00:27



2017-07-02 23:17

reporter   ~0101459

The screenshots show the behavior of the grid while the program is running, not the behavior of the grid in the development environment!

In Delphi, the property - settings from the DFM - file are set as default values in context with the event procedure -> "Color = clMoneyGreen" or "Alignment = taCenter" of a column also active in the executed program.
The procedure "TDBGrid(Sender).DefaultDrawColumnCell(Rect,DataCol,Column,State)" set the values from the DFM - File. (Delphi102_DefaultDraw_False.jpg)

In Lazarus, at same approach, the values from the LFM file (in the example "clMoneyGreen" and "taCenter") are not active as default values. In the execute programm the procedure "TDBGrid(Sender).DefaultDrawColumnCell(Rect,DataCol,Column,State)" set the values to "clWhite" and "taLeftJustify" and so on. (DefaultDraw_False.jpg).


2017-07-03 00:03

developer   ~0101460

Maybe you are right. But please post a Lazarus project showing the issue. But no UNIDAC components, use standard databases.


2017-07-03 23:24

reporter (781,664 bytes)


2017-07-03 23:26

reporter   ~0101478

I've build a test application with standard components.


2017-07-04 10:49

developer   ~0101485

Last edited: 2017-07-04 13:58

View 7 revisions

Thanks for the demo, now I see things clearer: basically, you want to replace the string displayed for date 0 with an empty string, but keep the rest unchanged.

I played a lot with your demo and compared it with TStringGrid, and I think the current behavior is (almost) consistent. It does break Delphi compatibility, but the Lazarus grids are more versatile and not Delphi-compatible into the finest detail anyway...

So what is wrong in your demo? In Lazarus, application of a custom cell painting handler (OnDrawColumnCell) and turning DefaultDrawing off are two separate options to control the grid. Read the documentation in for the details. In short: the property DefaultDrawing refers essentially to default *background* drawing only. So, when DefaultDrawing is ON the grid paints the background according to the parameters set up in the PrepareCanvas method and/or the OnPrepareCanvas event; the OnDrawColumnCell method then can be used to control text painting separately. That's the way you should go: Return DefaultDrawing to true (i.e. use background as defined by the columns), and use your OnDrawColumnCell code (i.e. erase date=0 cells). There's one issue, though: The text already has been painted, and therefore you must call FillRect in the OnDrawColumnCell handler before your own code; otherwise the old cell text of the date=0 cells will remain.

  procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
    DataCol: Integer; Column: TColumn; State: TGridDrawState);
    if (Column.Field.AsString = '30.12.1899') then

Or better, since the text already has been painted, why call DefaultDrawColumnCell and paint an empty string at all?

  procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
    DataCol: Integer; Column: TColumn; State: TGridDrawState);
    if (Column.Field.AsString = '30.12.1899') then

This demonstrates the Lazarus stragegy if DefaultDrawing is true: you only paint those cells which are to be changed.

On the other hand, if DefaultDrawing is OFF, all the painting is up to your OnDrawColumnCell handler. It is a matter of taste whether the canvas should pick up the text alignment, background color etc proposed by the column properties - using an OnDrawColumnCell handler with DefaultDrawing = false tells the grid that you want to do everything by yourself, so why waste resources on some setup that you might want to change anyway?


2017-07-04 15:18

reporter   ~0101490

Great, thank you very much!!!


2017-07-04 15:41

developer   ~0101491

Thank you for your patience... So, I'll assign the report to myself and resolve as "No change required"?


2017-07-05 18:32

reporter   ~0101511

Yes, no change required.


2017-07-05 19:14

developer   ~0101512

Finally, close the report.

Issue History

Date Modified Username Field Change
2015-11-09 15:29 Uli New Issue
2015-11-09 23:06 Maxim Ganetsky Relationship added related to 0024039
2015-11-09 23:07 Maxim Ganetsky LazTarget => -
2015-11-09 23:07 Maxim Ganetsky Summary If the DBGRID - property "DefaultDrawing" set to FALSE the properties of column titels AND Cells are lost => If the DBGRID DefaultDrawing property set to FALSE the properties of column titles AND Cells are lost
2016-04-26 01:44 Jesus Reyes Fixed in Revision => 46408
2016-04-26 01:44 Jesus Reyes Note Added: 0092227
2016-04-26 01:44 Jesus Reyes Status new => resolved
2016-04-26 01:44 Jesus Reyes Fixed in Version => 1.3 (SVN)
2016-04-26 01:44 Jesus Reyes Resolution open => fixed
2016-04-26 01:44 Jesus Reyes Assigned To => Jesus Reyes
2017-06-10 17:20 Uli Note Added: 0100996
2017-06-10 17:20 Uli Status resolved => assigned
2017-06-10 17:20 Uli Resolution fixed => reopened
2017-06-23 22:27 Uli File Added: DefaultDraw_TRUE.jpg
2017-06-23 22:28 Uli File Added: DefaultDraw_FALSE.jpg
2017-06-23 22:28 Uli File Added: OnDrawColumnCell.jpg
2017-06-23 22:32 Uli Note Added: 0101312
2017-06-24 00:59 wp Note Added: 0101314
2017-06-25 19:35 wp Note Edited: 0101314 View Revisions
2017-07-01 22:28 Uli File Added: Delphi102_DefaultDraw_TRUE.jpg
2017-07-01 22:29 Uli File Added: Delphi102_DefaultDraw_FALSE.jpg
2017-07-01 23:14 Uli File Added:
2017-07-01 23:18 Uli Note Added: 0101418
2017-07-02 00:25 wp Note Added: 0101419
2017-07-02 00:27 wp File Added: D101_DBGrid_DefaultDrawing_OFF.jpg
2017-07-02 01:13 wp Note Edited: 0101419 View Revisions
2017-07-02 23:17 Uli Note Added: 0101459
2017-07-03 00:03 wp Note Added: 0101460
2017-07-03 23:24 Uli File Added:
2017-07-03 23:26 Uli Note Added: 0101478
2017-07-04 10:49 wp Note Added: 0101485
2017-07-04 10:52 wp Note Edited: 0101485 View Revisions
2017-07-04 10:58 wp Note Edited: 0101485 View Revisions
2017-07-04 11:00 wp Note Edited: 0101485 View Revisions
2017-07-04 11:01 wp Note Edited: 0101485 View Revisions
2017-07-04 13:52 wp Note Edited: 0101485 View Revisions
2017-07-04 13:58 wp Note Edited: 0101485 View Revisions
2017-07-04 15:18 Uli Note Added: 0101490
2017-07-04 15:41 wp Note Added: 0101491
2017-07-05 18:32 Uli Note Added: 0101511
2017-07-05 19:14 wp Note Added: 0101512
2017-07-05 19:14 wp Status assigned => resolved
2017-07-05 19:14 wp Resolution reopened => no change required
2017-07-05 19:14 wp Assigned To Jesus Reyes => wp