Board index » delphi » How to color 1 row in a DBGrid

How to color 1 row in a DBGrid

Hi,

I would like to be able to color the row where the focus is.
Does someone know how to do that?

TIA

michiel

 

Re:How to color 1 row in a DBGrid


Quote
> I would like to be able to color the row where the focus is.
> Does someone know how to do that?

It depends. If you want just to mark the whole row instead of one value of
the row, you can do it with default blue color:

DBGrid properties - Options - dgRowSelect - True.

Re:How to color 1 row in a DBGrid


You are right, the row is colored.
But it also blocks the editing.
No, I would like to be able to show the user, with a self chosen light color
(in stead of the full Navy blue), which item on the left side belongs to the
field he's editing on the right side.

I also tried Options - dgIndicator - True as a way of giving that
information.
Not bad, and I can give it the desired color, but then the vertical
scrollbar behaves very different from when the Indicator is off. It actually
turns the scrollbar almost useless.
Or does anyone know of a solution for this behavior?

TIA
(and Neven Horvat, thanks for your reaction)

michiel

"Neven Horvat" <neven.horv...@ck.tel.hr> schreef in bericht
news:9sjbfl$8fv0$1@as201.hinet.hr...

Quote
> > I would like to be able to color the row where the focus is.
> > Does someone know how to do that?

> It depends. If you want just to mark the whole row instead of one value of
> the row, you can do it with default blue color:

> DBGrid properties - Options - dgRowSelect - True.

Re:How to color 1 row in a DBGrid


You can use the OnDrawDataColumnCell Event e.g.:

procedure TESF_Form.dagEmplTrngDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
var
  OldColor: TColor;
begin

  if (esfdata.qry_EmpTrng['PXREMPL_TRNG_COMPLETED']  = null)
{ fo. The cell is not heighlighted. Red text on blue backgrount looks ugly. }
  and (dagEmplTrng.Canvas.Brush.Color <> dagEmplTrng.AltColors.Highlight)
    then begin
    OldColor := dagEmplTrng.Canvas.Font.Color;
    dagEmplTrng.Canvas.Font.Color := clRed;
    dagEmplTrng.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    if gdFocused in State then begin
{ fo. Windows draws the focus rect with the inversed fonts's color. }
      dagEmplTrng.Canvas.Font.Color := OldColor;
      Windows.DrawFocusRect(dagEmplTrng.Canvas.Handle, Rect);
    end;
  end;
end;

I used DBAltGrid, and the "dagEmplTrng" is the grid. Note: do not attempt to
change the colors of the grid or it's properties directly. You must use the
Canvas property and drill down to background color and font color.

Actually if you don't have DBAltGrid, you are missing out on a fine tool. You
can get more info on DBAltGrid at  http://www.quasidata.com/

Tom Repstad
University of Vermont

Quote
Michiel Rapati-Kekkonen wrote:
> You are right, the row is colored.
> But it also blocks the editing.
> No, I would like to be able to show the user, with a self chosen light color
> (in stead of the full Navy blue), which item on the left side belongs to the
> field he's editing on the right side.

> I also tried Options - dgIndicator - True as a way of giving that
> information.
> Not bad, and I can give it the desired color, but then the vertical
> scrollbar behaves very different from when the Indicator is off. It actually
> turns the scrollbar almost useless.
> Or does anyone know of a solution for this behavior?

> TIA
> (and Neven Horvat, thanks for your reaction)

> michiel

> "Neven Horvat" <neven.horv...@ck.tel.hr> schreef in bericht
> news:9sjbfl$8fv0$1@as201.hinet.hr...
> > > I would like to be able to color the row where the focus is.
> > > Does someone know how to do that?

> > It depends. If you want just to mark the whole row instead of one value of
> > the row, you can do it with default blue color:

> > DBGrid properties - Options - dgRowSelect - True.

Other Threads