Sign in Join

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

Mailing lists / lazarus / 2009-09

DBGrid.OnDrawColumnCell

8 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

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

Andrea Mauri

Dear all,
in my application I need to change the cell color of some cells in a DBGrid. I use the OnDrawColumnCell event. My DBGrid name is dbgLoadings here the OnDrawColumnCell event:

procedure TfrmPCA.dbgLoadingsDrawColumnCell(Sender: TObject; const Rect:
TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if DataCol >= 2 then
  begin
     dbgLoadings.Canvas.Font.Color:= clWhite;
     dbgLoadings.Canvas.Brush.Color:= clRed;
  end;
  if DataCol >= 2 then
    dbgLoadings.DefaultDrawColumnCell
      (Rect, DataCol, Column, State);
end;

It does not work. The Font appears fuzzy coloured like if the white font is written upon the original balck one. And the foreground of the cell remain white.

Any hint?
Regards,
Andrea

Reply by email

Luca Olivetti
to Andrea Mauri

En/na Andrea Mauri ha escrit:

Show quoted text 27 lines
Dear all, in my application I need to change the cell color of some cells in a DBGrid. I use the OnDrawColumnCell event. My DBGrid name is dbgLoadings here the OnDrawColumnCell event: procedure TfrmPCA.dbgLoadingsDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin if DataCol >= 2 then begin dbgLoadings.Canvas.Font.Color:= clWhite; dbgLoadings.Canvas.Brush.Color:= clRed; end; if DataCol >= 2 then dbgLoadings.DefaultDrawColumnCell (Rect, DataCol, Column, State); end; It does not work. The Font appears fuzzy coloured like if the white font is written upon the original balck one. And the foreground of the cell remain white. Any hint? Regards, Andrea

I leave DefaultDrawing to true and use the OnPrepareCanvas event to do that. See also
http://wiki.freepascal.org/Grids_Reference_Page

Bye

Luca Olivetti Wetron Automatizaci?n S.A. http://www.wetron.es/ Tel. +34 93 5883004 (Ext.133) Fax +34 93 5883007

Reply by email

matt shaffer
to Luca Olivetti

I thought I'd just throw this out there:
I'm still having issues with CPU usage and my customized grid. How often is prepare canvas called? I would think only when the form would be moving or otherwise need moving, but I suspect it's being called constantly. The grid is quite customized, changing alignment for most cells, checking the strings of every single cell and changing their fonts and backgrounds accordingly.. I'll throw in the code if anyone's interested.

Luca Olivetti wrote 50 lines
En/na Andrea Mauri ha escrit: > Dear all, > in my application I need to change the cell color of some cells in a > DBGrid. > I use the OnDrawColumnCell event. My DBGrid name is dbgLoadings here the > OnDrawColumnCell event: > > procedure TfrmPCA.dbgLoadingsDrawColumnCell(Sender: TObject; const Rect: > TRect; > DataCol: Integer; Column: TColumn; State: TGridDrawState); > begin > if DataCol >= 2 then > begin > dbgLoadings.Canvas.Font.Color:= clWhite; > dbgLoadings.Canvas.Brush.Color:= clRed; > end; > if DataCol >= 2 then > dbgLoadings.DefaultDrawColumnCell > (Rect, DataCol, Column, State); > end; > > It does not work. The Font appears fuzzy coloured like if the white font > is written upon the original balck one. And the foreground of the cell > remain white. > > Any hint? > Regards, > Andrea > I leave DefaultDrawing to true and use the OnPrepareCanvas event to do that. See also http://wiki.freepascal.org/Grids_Reference_Page Bye -- Luca Olivetti Wetron Automatizaci?n S.A. http://www.wetron.es/ Tel. +34 93 5883004 (Ext.133) Fax +34 93 5883007 -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20090917/f08549ae/attachment.html>

Reply by email

Vincent Snijders
to matt shaffer
matt shaffer wrote
I thought I'd just throw this out there: I'm still having issues with CPU usage and my customized grid.

I thought I'd just throw this out:
Did you follow Jesus's last advice to which you did not respond?

If using OnPrepareCanvas event, try to use Canvas properties instead of grids properties ...

Read further in the original mail.

Vincent

Reply by email

Serge Girard via Orange
to matt shaffer: I thought I'd just throw this out there: I'm still having issues with CPU usage and my…

matt shaffer a ?crit :

Show quoted text 72 lines
I thought I'd just throw this out there: I'm still having issues with CPU usage and my customized grid. How often is prepare canvas called? I would think only when the form would be moving or otherwise need moving, but I suspect it's being called constantly. The grid is quite customized, changing alignment for most cells, checking the strings of every single cell and changing their fonts and backgrounds accordingly.. I'll throw in the code if anyone's interested. On Thu, Sep 17, 2009 at 6:08 AM, Luca Olivetti < <mailto:>> wrote: En/na Andrea Mauri ha escrit: Dear all, in my application I need to change the cell color of some cells in a DBGrid. I use the OnDrawColumnCell event. My DBGrid name is dbgLoadings here the OnDrawColumnCell event: procedure TfrmPCA.dbgLoadingsDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin if DataCol >= 2 then begin dbgLoadings.Canvas.Font.Color:= clWhite; dbgLoadings.Canvas.Brush.Color:= clRed; end; if DataCol >= 2 then dbgLoadings.DefaultDrawColumnCell (Rect, DataCol, Column, State); end; It does not work. The Font appears fuzzy coloured like if the white font is written upon the original balck one. And the foreground of the cell remain white. Any hint? Regards, Andrea I leave DefaultDrawing to true and use the OnPrepareCanvas event to do that. See also http://wiki.freepascal.org/Grids_Reference_Page Bye -- Luca Olivetti Wetron Automatizaci?n S.A. http://www.wetron.es/ Tel. +34 93 5883004 (Ext.133) Fax +34 93 5883007 -- _______________________________________________ Lazarus mailing list <mailto:> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus ------------------------------------------------------------------------ -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Hello

use the OnPrepareCanvas instead of onDrawColumnCell (Bad Delphi Custom lol )
here is an sample

procedure TForm1.DBGrid1PrepareCanvas(sender: TObject; DataCol: Integer;
  Column: TColumn; AState: TGridDrawState);
begin
   with (Sender as TDBGrid) do
    begin
      if (DataCol=0) OR (DataSource.DataSet.FieldByName('ID').asInteger<0)
       then begin
           Canvas.Brush.Color:=FixedColor;   // or whatever color wanted
           Canvas.Font.Color:=clWindowText; // idem
         // Canvas.TextStyle.Alignment:=taCenter     another tip to
center the text in the cell
      end;
   end;
end;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20090917/517056b6/attachment.html>

Reply by email

Andrea Mauri
to Luca Olivetti: En/na Andrea Mauri ha escrit: I leave DefaultDrawing to true and use the OnPrepareCanvas…

it works, thanks!
andrea

Luca Olivetti ha scritto:

Show quoted text 36 lines
En/na Andrea Mauri ha escrit: > Dear all, > in my application I need to change the cell color of some cells in a > DBGrid. > I use the OnDrawColumnCell event. My DBGrid name is dbgLoadings here > the OnDrawColumnCell event: > > procedure TfrmPCA.dbgLoadingsDrawColumnCell(Sender: TObject; const > Rect: TRect; > DataCol: Integer; Column: TColumn; State: TGridDrawState); > begin > if DataCol >= 2 then > begin > dbgLoadings.Canvas.Font.Color:= clWhite; > dbgLoadings.Canvas.Brush.Color:= clRed; > end; > if DataCol >= 2 then > dbgLoadings.DefaultDrawColumnCell > (Rect, DataCol, Column, State); > end; > > It does not work. The Font appears fuzzy coloured like if the white > font is written upon the original balck one. And the foreground of > the cell remain white. > > Any hint? > Regards, > Andrea I leave DefaultDrawing to true and use the OnPrepareCanvas event to do that. See also http://wiki.freepascal.org/Grids_Reference_Page Bye

Reply by email

Matt Shaffer
to Vincent Snijders: I thought I'd just throw this out: Did you follow Jesus's last advice to which you did…

No, I must have missed that email altogether. Could you forward me the message if possible? (dazappa.matt @ gmail.com) As I cannot find it in my inbox, on mailarchive, or on the FPC mail archives.. If the email is on the web and I have missed it, I would like to know.

On Thu, Sep 17, 2009 at 9:12 AM, Vincent Snijders <

Show quoted text 27 lines
wrote: matt shaffer schreef: > I thought I'd just throw this out there: > I'm still having issues with CPU usage and my customized grid. > I thought I'd just throw this out: Did you follow Jesus's last advice to which you did not respond? > If using OnPrepareCanvas event, try to use Canvas properties instead of > grids properties ... > Read further in the original mail. Vincent -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20090917/3c2994d2/attachment.html>

Reply by email

Vincent Snijders
to Matt Shaffer
Matt Shaffer wrote 6 lines
No, I must have missed that email altogether. Could you forward me the message if possible? (dazappa.matt @ gmail.com <http://gmail.com>) As I cannot find it in my inbox, on mailarchive, or on the FPC mail archives.. If the email is on the web and I have missed it, I would like to know.

I guess Graeme hijacked the thread ;-)

See:
http://lists.lazarus.freepascal.org/pipermail/lazarus/2009-August/044804.html

Vincent

Reply by email