Board index » delphi » DBGrid - make cell data to color / bold

DBGrid - make cell data to color / bold

Hi,
I would like to change the data on the DBGrid cell to a color
or make it bold when my query has met certain conditions.
How to do it?

Thanks.
sam

 

Re:DBGrid - make cell data to color / bold


You must use OnDrawDataCell event of grid. If you'll scroll messages in
forum, you'll find a lot of samples

--
With best regards, Mike Shkolnik
EMail: mshkol...@scalabium.com
http://www.scalabium.com

"sam" <samuell...@hotmail.com> ???Y/???Y ????? ???Y??:
news:3ec8dd8e$1@newsgroups.borland.com...

Quote

> Hi,
> I would like to change the data on the DBGrid cell to a color
> or make it bold when my query has met certain conditions.
> How to do it?

> Thanks.
> sam

Re:DBGrid - make cell data to color / bold


Quote
"sam" <samuell...@hotmail.com> wrote in message

news:3ec8dd8e$1@newsgroups.borland.com...

Quote

> Hi,
> I would like to change the data on the DBGrid cell to a color
> or make it bold when my query has met certain conditions.
> How to do it?

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
 const Rect: TRect;  DataCol: Integer; Column: TColumn;
 State: TGridDrawState);
begin
    if (Column.FieldName = 'STATUS') and
         (Column.Field.AsString = 'FAULTY') then
      Dbgrid1.Canvas.Font.Color := clRed;
    Dbgrid1.DefaultDrawColumnCell(Rect, DataCol,
    Column, State);
end;
-------
jacob

Re:DBGrid - make cell data to color / bold


Hi,
Thanks for your help. I have tried your method but it
highlighted the whole row. What I want is only a particular
cell change the color or font. How to do it?

I have tried using onDrawDataCell. But I found that, I can't
trigger the event. It seems like the program does not run this procedure. I saw an example saying that I need to set the
default drawing to true. But i don't know how?

sam.

Quote
"jacob muntner" <jaco...@hotmail.co.il> wrote:
>"sam" <samuell...@hotmail.com> wrote in message
>news:3ec8dd8e$1@newsgroups.borland.com...

>> Hi,
>> I would like to change the data on the DBGrid cell to a color
>> or make it bold when my query has met certain conditions.
>> How to do it?

>procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
> const Rect: TRect;  DataCol: Integer; Column: TColumn;
> State: TGridDrawState);
>begin
>    if (Column.FieldName = 'STATUS') and
>         (Column.Field.AsString = 'FAULTY') then
>      Dbgrid1.Canvas.Font.Color := clRed;
>    Dbgrid1.DefaultDrawColumnCell(Rect, DataCol,
>    Column, State);
>end;
>-------
>jacob

Re:DBGrid - make cell data to color / bold


You must use OnDrawColumnCell, NOT OnDrawDataCell

Stephan

Quote
sam wrote:
> Hi,
> Thanks for your help. I have tried your method but it
> highlighted the whole row. What I want is only a particular
> cell change the color or font. How to do it?

> I have tried using onDrawDataCell. But I found that, I can't
> trigger the event. It seems like the program does not run this procedure. I saw an example saying that I need to set the
> default drawing to true. But i don't know how?

Re:DBGrid - make cell data to color / bold


Quote
"sam" <samuell...@hotmail.com> wrote in message

news:3ec8ebf8$1@newsgroups.borland.com...
Quote

> Hi,
> Thanks for your help. I have tried your method but it
> highlighted the whole row. What I want is only a particular
> cell change the color or font. How to do it?

......
[snip]

Quote
> I saw an example saying that I need to set the
> default drawing to true. But i don't know how?

'DefaultDrawing'  IS a property of TDBGrid, just set it to
TRUE in the Object Inspector.
-----
jacob

Re:DBGrid - make cell data to color / bold


I have set the DefaultDrawing to true but the result is still
the same. It highligted whole row, but what I want is hightlight a particular cell only.

sam

Quote
"jacob muntner" <jaco...@hotmail.co.il> wrote:
>"sam" <samuell...@hotmail.com> wrote in message
>news:3ec8ebf8$1@newsgroups.borland.com...

>> Hi,
>> Thanks for your help. I have tried your method but it
>> highlighted the whole row. What I want is only a particular
>> cell change the color or font. How to do it?
>.......
>[snip]
>> I saw an example saying that I need to set the
>> default drawing to true. But i don't know how?

>'DefaultDrawing'  IS a property of TDBGrid, just set it to
>TRUE in the Object Inspector.
>-----
>jacob

Re:DBGrid - make cell data to color / bold


Hi,
I know how to do it already. I was using the wrong the syntax.
Thanks for your help.

sam.

Quote
"sam" <samuell...@hotmail.com> wrote:

>I have set the DefaultDrawing to true but the result is still
>the same. It highligted whole row, but what I want is hightlight a particular cell only.

>sam

>"jacob muntner" <jaco...@hotmail.co.il> wrote:
>>"sam" <samuell...@hotmail.com> wrote in message
>>news:3ec8ebf8$1@newsgroups.borland.com...

>>> Hi,
>>> Thanks for your help. I have tried your method but it
>>> highlighted the whole row. What I want is only a particular
>>> cell change the color or font. How to do it?
>>.......
>>[snip]
>>> I saw an example saying that I need to set the
>>> default drawing to true. But i don't know how?

>>'DefaultDrawing'  IS a property of TDBGrid, just set it to
>>TRUE in the Object Inspector.
>>-----
>>jacob

Other Threads