Board index » delphi » How change the color of column and row lines of DBGrid

How change the color of column and row lines of DBGrid

Hi all,

 How can I change the color of column and row lines of DBGrid?

Robbert.

 

Re:How change the color of column and row lines of DBGrid


Quote
Robbert Brackel wrote:

> Hi all,

>  How can I change the color of column and row lines of DBGrid?

> Robbert.

Hello !
 To change color in a TDBgrid-column:

 (where 'grid' is a TDBgrid and 'no' is the integer column-number,
  0 is the first column)

 grid.columns[no].color := <clColor>

 You can change font color by:

 grid.columns[no].font.color := <clColor>

 To change colors on individual rows, you have to access the OnDrawCell
and do some canvas paint. But keep in mind that this may slow down your
grid scrolling a bit.

Regards
Atle Markeng
DataMar, Oslo - Norway

Re:How change the color of column and row lines of DBGrid


Quote
Robbert Brackel wrote:

> Hi all,

>  How can I change the color of column and row lines of DBGrid?

> Robbert.Use the ondrawdatacell event, you can use the tfield parameter to

determine which collumn you are in.

Mike

Re:How change the color of column and row lines of DBGrid


Quote
Robbert Brackel <brac...@pi.net> wrote:
>Hi all,

> How can I change the color of column and row lines of DBGrid?

>Robbert.

Play around with this.
Obviously there are different ways that the selection tests can be
done.

procedure TfmDesktop.DBGrid1DrawDataCell(Sender: TObject;
  const Rect: TRect; Field: TField; State: TGridDrawState);
begin
  { this will make all cells in the first column green }
  if (Field.Index=0) then begin
    DBGrid1.Canvas.Font.Color := clGreen;
    DBGrid1.DefaultDrawDataCell(Rect, Field, State);
  end;

  { if the cell that contains the text 'PAYE' }
  { then the text will be in blue             }
  { and the LINES will be red                 }
  if (Field.DisplayText='PAYE') then begin
    DBGrid1.Canvas.Font.Color := clBlue;
    DBGrid1.DefaultDrawDataCell(Rect, Field, State);
    with Rect do
    begin
      DBGrid1.Canvas.Pen.Color := clRed;
      DBGrid1.Canvas.PolyLine([Point(Left, Bottom-1),
                               Point(Left, Top),
                               Point(Right, Top),
                               Point(Right,Bottom-1),
                               Point(Left, Bottom-1)]);
    end;
  end;

  { this will display all the cells in a row red }
  { if certain conditions are true in the record }
  { STAC is the data field name  }
  if (Query1STAC.AsString='CLOSED') then begin
    DBGrid1.Canvas.Font.Color := clRed;
    DBGrid1.DefaultDrawDataCell(Rect, Field, State);
  end;
end;

==
Bob Small

Other Threads