View Issue Details

IDProjectCategoryView StatusLast Update
0021496LazarusLCLpublic2012-03-21 09:24
ReporterReinier OlislagersAssigned ToJesus Reyes  
Status closedResolutionfixed 
Product Version0.9.31 (SVN) 
Fixed in Version0.9.31 (SVN) 
Summary0021496: [PATCH] Draw dbgrid header columns/rows when DefaultDrawing false
DescriptionWhen using DefaultDrawing false and running my own OnDrawColumnCell, fixed/header columns and rows are not drawn (see Windows screenshot).

The patch fixes this issue - tested on Windows and Linux x64.

Based on Ludo Brands' code in the forums:,16300.msg88285.html#msg88285

Steps To ReproduceRun sample program, import messages.csv. Grid header columns and rows will bleed through and no header text is drawn (see Windows screenshot).
Tested on Windows; on x64 Linux Lazarus r 35878, the bleed through does not happen, but the texts are not drawn in the header rows.
Probable low risk for other widgetsets as the patch only calls already existing DefaultDrawCell...
Additional InformationI've assigned it to the LCL category instead of database as it seems to be a pure drawing bug, not a database-specific item. Don't know if this issue also happens on other grids. Also, dbgrids.pas is in the lcl directory :)

It seems the OnDefaultDrawing event does not fire on header rows/columns.
Delphi XE2 DefaultDrawColumnCell documentation would imply that OnDrawColumnCell is fired for all cells, including header cells.
However, looking at the LCL code - it uses DataCol, it seems it is only intended for data cells (non-header cells).
Perhaps the XE2 documentation is wrong - or I interpreted it incorrectly ;)

TagsNo tags attached.
Fixed in Revision36180
WidgetsetGTK 2, Win32/Win64
Attached Files


2012-03-17 09:22


DBGridCustomDrawHeader.diff (826 bytes)   
Index: lcl/dbgrids.pas
--- lcl/dbgrids.pas	(revision 36074)
+++ lcl/dbgrids.pas	(working copy)
@@ -2750,11 +2750,15 @@
   if (ARow>=FixedRows) and Assigned(OnDrawColumnCell) and
     not (csDesigning in ComponentState) then begin
     DataCol := ColumnIndexFromGridColumn(aCol);
     if DataCol>=0 then
-      OnDrawColumnCell(Self, aRect, DataCol, TColumn(Columns[DataCol]), aState);
+      OnDrawColumnCell(Self, aRect, DataCol, TColumn(Columns[DataCol]), aState)
+    else //Fixed row?
+      DefaultDrawCell(aCol, aRow, aRect, aState);
+  end
+  else begin //Designing, or fixed column
+    if not DefaultDrawing then // don't draw twice
+      DefaultDrawCell(aCol, aRow, aRect, aState);
   DrawCellGrid(aCol, aRow, aRect, aState);
DBGridCustomDrawHeader.diff (826 bytes)   

2012-03-17 09:22 (13,971 bytes)

2012-03-17 09:22


gridheaders.png (57,169 bytes)   
gridheaders.png (57,169 bytes)   

Jesus Reyes

2012-03-20 20:01

developer   ~0057857

Thanks for the patch, I have not applied as is because it draws twice fixed columns which made indicator cell appear black.

Indeed, it seems delphi dbgrid do not allow to do custom fixed cells drawing.

Please tests

Reinier Olislagers

2012-03-21 09:24

developer   ~0057868

Thanks, Jesus, works perfectly on Win32 on today's SVN.

Issue History

Date Modified Username Field Change
2012-03-17 09:22 Reinier Olislagers New Issue
2012-03-17 09:22 Reinier Olislagers File Added: DBGridCustomDrawHeader.diff
2012-03-17 09:22 Reinier Olislagers Widgetset => GTK 2, Win32/Win64
2012-03-17 09:22 Reinier Olislagers File Added:
2012-03-17 09:22 Reinier Olislagers File Added: gridheaders.png
2012-03-17 09:32 Jesus Reyes Status new => assigned
2012-03-17 09:32 Jesus Reyes Assigned To => Jesus Reyes
2012-03-20 20:01 Jesus Reyes Fixed in Revision => 36180
2012-03-20 20:01 Jesus Reyes LazTarget => 0.99.0
2012-03-20 20:01 Jesus Reyes Status assigned => resolved
2012-03-20 20:01 Jesus Reyes Fixed in Version => 0.9.31 (SVN)
2012-03-20 20:01 Jesus Reyes Resolution open => fixed
2012-03-20 20:01 Jesus Reyes Note Added: 0057857
2012-03-20 20:01 Jesus Reyes Target Version => 0.99.0
2012-03-21 09:24 Reinier Olislagers Status resolved => closed
2012-03-21 09:24 Reinier Olislagers Note Added: 0057868