--- El vie 22-ene-10, Graeme Geldenhuys escribi?:
Show quoted text 9 lines
De:: Graeme Geldenhuys
Asunto: [Lazarus] DBGrid highlighting certain cells
A: "Lazarus mailing list"
Fecha: viernes 22 de enero de 2010, 0:47
Hi,
What is the recommended way of highlighting (by changing
cell background
color) certain cells based on there display value?
The recommended way is using OnPrepareCanvas DbGrid event.
Show quoted text 12 lines
In Delphi I did the following:
* DefaultDrawing = False
* OnDrawDataCell I implemented the following.
? ? Check for criteria, then set Brush.Color
? ? Then call DefaultDrawDataCell
This saves me the trouble from having to manually draw
everything like the
background color, border, text etc...
Using OnPrepareCanvas you don't have to draw anything, you get the column:tcolumn which is being painted as an argument and from there you get the field and can take decisions based on fields value, then you change dbgrid's canvas properties, for cell background you will have to adjust grid.canvas.brush.color, font changes can be made on grid.canvas.font, alignment, etc.
for borders one needs custom drawing and OnDrawColumnCell is needed, OnPrepareCanvas do not help here.
Show quoted text 7 lines
Unfortunately this "easy" method is not possible with
Lazarus, because
DefaultDrawColumnCell doesn't paint the background (only
text), it is done
somewhere else (not sure where). Is this an oversight, or
by design?
I think until now nobody noted the problem, probably this feature is not used too much. But IIRC, the background was supposed to be painted in OnDrawColumnCell and then you call DefaultDrawColumnCell, I might have mis understood how this works, I need a good test case.
If by design, what is the recommended way of doing this?
Although with OnPrepareCanvas we cover most of cases where this feature is needed I would like to make it Delphi compatible, if possible, please submit a bug report.
Regards,
? - Graeme -
Jesus Reyes A.
Encuentra las mejores recetas en Yahoo! Cocina.
http://mx.mujer.yahoo.com/cocina/