Board index » delphi » Different Colors in String Grid??

Different Colors in String Grid??

Hello,

how can i make my StringGrid-Cells colored. In different color, for each
cell?

cu

christian

## CrossPoint v3.11 R ##

 

Re:Different Colors in String Grid??


In article <6MgIkBTH...@p-ckoe.link-n.cl.sub.de>, CH.KOER...@LINK-N.cl.sub.de
says...

Quote

>Hello,

>how can i make my StringGrid-Cells colored. In different color, for each
>cell?

>cu

>christian

>## CrossPoint v3.11 R ##

Check out

http://loki.borland.com/winbin/bds.exe?getdoc+2903+Delphi

This is a document on how to have different color characters in a string grid.
 Maybe it will shed some light?

It basically uses the OnDrawCell event to change font color.  

Hope this sheds some light.
Chris <csu...@acxiom.com>

Re:Different Colors in String Grid??


You have to turn off the Default drawing and in the OnDrawDataCell event,
change the brush color and paint the rect being passed in.

Christian Koerner <CH.KOER...@LINK-N.cl.sub.de> wrote in article
<6MgIkBTH...@p-ckoe.link-n.cl.sub.de>...

Quote
> Hello,

> how can i make my StringGrid-Cells colored. In different color, for each
> cell?

> cu

> christian

> ## CrossPoint v3.11 R ##

Re:Different Colors in String Grid??


My solution to this problem was to modify the StringGrid component
(sideways copy to another class) so it had a CellFont property, that allows
me to set the font on a cell by cell basis (The colour is tied to the Font
in Delphi, so you have to change the font to alter the colour).

Alistair.

Jason Jones <jaso...@admin.cdw.com> wrote in article
<01bbe913$e719d1a0$45949...@jasojon.cdw.com>...

Quote
> You have to turn off the Default drawing and in the OnDrawDataCell event,
> change the brush color and paint the rect being passed in.

> Christian Koerner <CH.KOER...@LINK-N.cl.sub.de> wrote in article
> <6MgIkBTH...@p-ckoe.link-n.cl.sub.de>...
> > Hello,

> > how can i make my StringGrid-Cells colored. In different color, for
each
> > cell?
> > [snip]

Re:Different Colors in String Grid??


Try this code. Leave the DefaultDrawing as true and add the following code to the
OnDrawCell method of the TStringGrid object.

procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: Longint;
  Rect: TRect; State: TGridDrawState);
const
  Offset = 3; {Keep away from the edge of the rect.}
begin
  with StringGrid1.canvas do
  begin
    { Text in the first column will be red. Note! You need only redraw
      those cells where you want to make modifications }
    if Col = 0 then begin
      font.color := clRed;
      textout(rect.left + Offset, rect.top + Offset,StringGrid1.Cells[Col,Row]);
    end;
  end;
end;

Eero Penttinen

Quote
Alistair Ward wrote:

> My solution to this problem was to modify the StringGrid component
> (sideways copy to another class) so it had a CellFont property, that allows
> me to set the font on a cell by cell basis (The colour is tied to the Font
> in Delphi, so you have to change the font to alter the colour).

> Alistair.

> Jason Jones <jaso...@admin.cdw.com> wrote in article
> <01bbe913$e719d1a0$45949...@jasojon.cdw.com>...
> > You have to turn off the Default drawing and in the OnDrawDataCell event,
> > change the brush color and paint the rect being passed in.

> > Christian Koerner <CH.KOER...@LINK-N.cl.sub.de> wrote in article
> > <6MgIkBTH...@p-ckoe.link-n.cl.sub.de>...
> > > Hello,

> > > how can i make my StringGrid-Cells colored. In different color, for
> each
> > > cell?
> > > [snip]

Re:Different Colors in String Grid??


Go here

http://www.borland.com/techsupport/delphi/devcorner/techtips/colorgrd...

He shows you how to add color to your DBGrid I imagine The code is
very simalur to a String Grid.

On 11 Dec 96 00:00:00 GMT, CH.KOER...@LINK-N.cl.sub.de (Christian

Quote
Koerner) wrote:
>Hello,

>how can i make my StringGrid-Cells colored. In different color, for each
>cell?

>cu

>christian

>## CrossPoint v3.11 R ##

Other Threads