Board index » delphi » fonts in DB grid

fonts in DB grid

I have a dbgrid & I would like to change the colour & the font to suite....

Let me explain the circumstance..

I am recording jobs...each job has a status....I want each status to be a
different colour & cancelled jobs to have a strikethrough....

I have tried to use the code on Borlands website but it only works if all
the coloumns are in the grid. I have used only three of the possible 10 or
so.

code I have tried include..

procedure TForm11.FormShow(Sender: TObject);
begin
if  table1.FieldByName('JOB_STATUS').value ='Completed' then
   dbgrid1.Font.Style:=[fsStrikeout] else dbgrid1.font.style:=[ ];

end;

AND

procedure TForm11.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  Field: TField; State: TGridDrawState);
begin

  if (Sender as
TDBGrid).DataSource.DataSet.FieldByName('JOB_Status').AsString ='Completed'
then
     Font.Style := [fsStrikeOut];
      end;

Can anyone help me please...

Thanks in advance

Charl...@netactive.co.za

 

Re:fonts in DB grid


Quote
In article <7p8uhm$oo...@forums.borland.com>, Charlie wrote:
> then
>      Font.Style := [fsStrikeOut];

Try:

  then Canvas.Font.Style := [fsStrikeOut];

 Mike Orriss (TeamB)
 (Unless stated otherwise, my replies relate to Delphi 4.03)
 (Unsolicited e-mail replies will most likely be ignored)

Re:fonts in DB grid


On Mon, 16 Aug 1999 14:23:21 +0100, "Mike Orriss (TeamB)"

Quote
<m...@3kcc.co.uk> wrote:
>Try:

>  then Canvas.Font.Style := [fsStrikeOut];

Mike,

DBGrid1.Canvas.Font.Style := [fsStrikeOut];  ?

Jan

Re:fonts in DB grid


Quote
In article <37b84a1c.471521...@forums.inprise.com>, Jan Sprengers wrote:
> DBGrid1.Canvas.Font.Style := [fsStrikeOut];  ?

Yep, oops, thanks.

 Mike Orriss (TeamB)
 (Unless stated otherwise, my replies relate to Delphi 4.03)
 (Unsolicited e-mail replies will most likely be ignored)

Re:fonts in DB grid


Sorry Mike that didn't work either..

On Mon, 16 Aug 1999 14:23:21 +0100, "Mike Orriss (TeamB)"

Quote
<m...@3kcc.co.uk> wrote:
>In article <7p8uhm$oo...@forums.borland.com>, Charlie wrote:
>> then
>>      Font.Style := [fsStrikeOut];

>Try:

>  then Canvas.Font.Style := [fsStrikeOut];

> Mike Orriss (TeamB)
> (Unless stated otherwise, my replies relate to Delphi 4.03)
> (Unsolicited e-mail replies will most likely be ignored)

Re:fonts in DB grid


Quote
In article <37b97cce.936...@forums.inprise.com>, Charlie Paterson wrote:
> Sorry Mike that didn't work either..

Try adding columns to the grid and place code in the OnDrawColumnCell
event handler like:

  Column.Font.Style := [fsStrikeOut];

 Mike Orriss (TeamB)
 (Unless stated otherwise, my replies relate to Delphi 4.03)
 (Unsolicited e-mail replies will most likely be ignored)

Re:fonts in DB grid


Mike I did that but then all the columns show FSstrikout not just the
completed ones..
I have 4 status's  
 'Completed'  
'Scheduled'  
'Cancelled'  &  
'In Progress'

I have added 3 columns to the DBgrid
 JOB_STATUS
 JOB_DATE
 JOB_PROCEDURES

Here is my procedure

procedure TForm11.DBGrid1DrawColumnCell(Sender: TObject; const Rect:
TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
 if (Sender as
TDBGrid).DataSource.DataSet.FieldByName('JOB_Status').AsString
='Completed'
then
     column.Font.Style :=[fsStrikeOut];
end;

Any Other Ideas ?  :-)

Quote

Re:fonts in DB grid


In article <37b99898.8051...@forums.inprise.com>,
Charl...@netactive.co.za says...
---8<---
Quote

> Any Other Ideas ?  :-)

---8<---

Try this (untested)

procedure TForm11.DBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
  if Column.Field.FieldName = 'JOB_Status' then
    if TStringField(Column.Field).Value = 'Completed' then
      Column.Font.Style :=[fsStrikeOut];
end;

Cheers,
Carl

Re:fonts in DB grid


nope Carl that didn't work either...now no colums have fsstrikethrough

On Tue, 17 Aug 1999 19:00:46 +0100, car...@dircon.co.uk (Carl

Quote
Caulkett) wrote:
>In article <37b99898.8051...@forums.inprise.com>,
>Charl...@netactive.co.za says...
>---8<---

>> Any Other Ideas ?  :-)

>---8<---

>Try this (untested)

>procedure TForm11.DBGrid1DrawColumnCell(Sender: TObject;
>  const Rect: TRect; DataCol: Integer; Column: TColumn;
>  State: TGridDrawState);
>begin
>  if Column.Field.FieldName = 'JOB_Status' then
>    if TStringField(Column.Field).Value = 'Completed' then
>      Column.Font.Style :=[fsStrikeOut];
>end;

>Cheers,
>Carl

Re:fonts in DB grid


OOOOOPS  sorry   the colum with the status  shows all fonts.in
fsstrikeout

Re:fonts in DB grid


In article <37b9ab4b.12839...@forums.inprise.com>,
Charl...@netactive.co.za says...

Quote
> OOOOOPS  sorry   the colum with the status  shows all fonts.in
> fsstrikeout

Sorry about that Charlie, that last suggestion of mine was rubbish!

Try this (*TESTED*)

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect:
TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
  G: TDBGrid;
  C: TCanvas;
begin
  G := Sender as TDBGrid;
  C := G.Canvas;
  if Column.Field.FieldName = 'JOB_Status' then
    begin
      C.Font.Assign(G.Font);
      if TStringField(Column.Field).Value = 'Completed' then
        C.Font.Style :=[fsStrikeOut]
      else
        C.Font.Style :=[];
      if gdSelected in State then
        begin
          C.Brush.Color := clHighlight;
          C.Font.Color := clHighlightText;
        end;
      C.TextOut(Rect.Left + 2, Rect.Top + 2,        
         (StringField(Column.Field).Value);
    end;
end;

Cheers,
Carl

Re:fonts in DB grid


Quote
In article <37b99898.8051...@forums.inprise.com>, Charlie Paterson wrote:
> then
>      column.Font.Style :=[fsStrikeOut];

This needs to be:

  then
    column.Font.Style :=[fsStrikeOut]
  else
    column.Font.Style :=[];

Works for me. If you only want the strikeout in a single column, then you
can add a test such as:

  and Column.FieldName = 'JOB_Status'

 Mike Orriss (TeamB)
 (Unless stated otherwise, my replies relate to Delphi 4.03)
 (Unsolicited e-mail replies will most likely be ignored)

Re:fonts in DB grid


WEY HEY..I found a pattern to your code Mike....the strikeout is
appearing on the line below the status

eg

Completed
Completed    >strikeout
Scheduled   >strikeout
Scheduled
Completed
Cancelled     > strikeout

Quote

Re:fonts in DB grid


Quote
In article <37b9d243.22816...@forums.inprise.com>, Charlie Paterson wrote:
> .I found a pattern to your code Mike

You mean you found the pattern as to how you applied my code <g>

 Mike Orriss (TeamB)
 (Unless stated otherwise, my replies relate to Delphi 4.03)
 (Unsolicited e-mail replies will most likely be ignored)

Re:fonts in DB grid


NOT EXACTLY  :-)
I did send a prevoius message..but it didn't show up...

Carls code only highlighted the status column...& it was a bit beyond
me what the code was doing

Your code I understood but it always highlighted the record after the
completed one....

Quote
>> .I found a pattern to your code Mike

>You mean you found the pattern as to how you applied my code <g>

> Mike Orriss (TeamB)
> (Unless stated otherwise, my replies relate to Delphi 4.03)
> (Unsolicited e-mail replies will most likely be ignored)

Go to page: [1] [2]

Other Threads