Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-01

DBGrid highlighting certain cells

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

What is the recommended way of highlighting (by changing cell background color) certain cells based on there display value?

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...

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?

If by design, what is the recommended way of doing this?

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Jesus Reyes
to Graeme Geldenhuys

--- 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/

Reply by email

Andrea Mauri
to Jesus Reyes

Il 22/01/2010 8.34, Jesus Reyes ha scritto:

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.

I use OnPrepareCanvas in order to change color background and fonts of a grid. I encunter a problem with the font. I can set the font color but the Bold property does not work, any hint?
this is the code:

Canvas.Font.Bold:= True;
Canvas.Font.Color:= clSkyBlue;

The font are correctly drawn in clSkyBlue but are not set to bold. andrea

Reply by email

Graeme Geldenhuys
to Jesus Reyes: --- El vie 22-ene-10, Graeme Geldenhuys escribi?: The recommended way is using…

2010/1/22 Jesus Reyes :

The recommended way is using OnPrepareCanvas DbGrid event.

OK, thanks for the information.

for borders one needs custom drawing and OnDrawColumnCell is needed, OnPrepareCanvas do not help here.

Changing the border look is not really important to my example, so I'll ignore that for now.

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.

OK, I'll create a bug report and add a test case project for you. Thanks for the quick responses.

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Jesus Reyes
to Andrea Mauri: Il 22/01/2010 8.34, Jesus Reyes ha scritto: I use OnPrepareCanvas in order to change…

--- El vie 22-ene-10, Andrea Mauri escribi?:

Show quoted text 13 lines
I use OnPrepareCanvas in order to change color background and fonts of a grid. I encunter a problem with the font. I can set the font color but the Bold property does not work, any hint? this is the code: Canvas.Font.Bold:= True; Canvas.Font.Color:= clSkyBlue; The font are correctly drawn in clSkyBlue but are not set to bold. andrea

Strange but I confirmed the problem, if you use:

Canvas.Font.Style := Canvas.Font.Style + [fsBold];

it works, will try to find why is not working.

Jesus Reyes A.

Encuentra las mejores recetas en Yahoo! Cocina.
http://mx.mujer.yahoo.com/cocina/

Reply by email