Board index » delphi » How do I get selected line in db grid in color

How do I get selected line in db grid in color

Hi

I want to have selected line in a dbgrid in color. I am a bookseller and in
my data base I have some books out of print and I want to have this lines in
another color discriminaded from the book statut.
Any one can help?

Thank you very much
Claude Lec

 

Re:How do I get selected line in db grid in color


Set TDBGrid.DefaultDrawing to False and use something like the following
OnDrawColumnCell event handler:

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  with Sender as TDBGrid do
  begin
    // If not selected and out-of-print
    if (State = []) and Table1.FieldByName('OutOfPrint').AsBoolean then
      // Change background to red
      Canvas.Brush.Color := clRed;
    // Draw text in selected colors
    DefaultDrawColumnCell(Rect, DataCol, Column, State);
  end;
end;

"Claude" <livresp...@magic.fr> schreef in bericht
news:984681348.374916@casablanca.magic.fr...

Quote
> Hi

> I want to have selected line in a dbgrid in color. I am a bookseller and
in
> my data base I have some books out of print and I want to have this lines
in
> another color discriminaded from the book statut.
> Any one can help?

> Thank you very much
> Claude Lec

Other Threads