Board index » delphi » TDBGrid -- DBGridDrawColumnCell event

TDBGrid -- DBGridDrawColumnCell event

DBGridDrawColumnCell event has a COLUMN property but it doesn't have the ROW
property.  Is it possible that I can get the ROW property also as to which
row the grid is painting the data.  Any help would be greatly appreciated.

Thanks

 

Re:TDBGrid -- DBGridDrawColumnCell event


aj...@galtney.com (Amir Ajani) wrote in
<8jah82$q...@bornews.borland.com>:

Quote
>DBGridDrawColumnCell event has a COLUMN property but it doesn't have the
>ROW property.  Is it possible that I can get the ROW property also as to
>which row the grid is painting the data.  Any help would be greatly
>appreciated.

>Thanks

If you use the DataSource that is associated with the DBGrid, you will find
that it always points to the row being painted.

--
Ken Rachynski
Database Analyst
EVANS
http://evansonline.com/
ICQ: 61655368

Re:TDBGrid -- DBGridDrawColumnCell event


Yes the DBGrid is attached to a DataSource.  But how would I know which row#
it is painting on the screen.

What I'm trying to do is to change the color of alternate rows.  If I know
which row its working on then I can do something like this:

if (CurrentRow mod 2) = 0 then
  change color to PaleGreen
else
  change color to clWhite
end;

Quote
Ken Rachynski <krac...@evansconsoles.com> wrote in message

news:8F608120Ekrachynec@207.105.83.62...
Quote
> aj...@galtney.com (Amir Ajani) wrote in
> <8jah82$q...@bornews.borland.com>:

> >DBGridDrawColumnCell event has a COLUMN property but it doesn't have the
> >ROW property.  Is it possible that I can get the ROW property also as to
> >which row the grid is painting the data.  Any help would be greatly
> >appreciated.

> >Thanks

> If you use the DataSource that is associated with the DBGrid, you will
find
> that it always points to the row being painted.

> --
> Ken Rachynski
> Database Analyst
> EVANS
> http://evansonline.com/
> ICQ: 61655368

Re:TDBGrid -- DBGridDrawColumnCell event


aj...@galtney.com (Amir Ajani) wrote in <8jb1pj$9...@bornews.borland.com>:

Quote
>What I'm trying to do is to change the color of alternate rows.  If I know
>which row its working on then I can do something like this:

Ah, I see clearly now. I know I've seen such code around somewhere
recently, I just can't find it. I'm thinking of looking in CodeCentral, but
it appears to be down right now.

--
Ken Rachynski
Database Analyst
EVANS
http://evansonline.com/
ICQ: 61655368

Re:TDBGrid -- DBGridDrawColumnCell event


aj...@galtney.com (Amir Ajani) wrote in
<8jah82$q...@bornews.borland.com>:

Quote
>DBGridDrawColumnCell event has a COLUMN property but it doesn't have the
>ROW property.  Is it possible that I can get the ROW property also as to
>which row the grid is painting the data.  Any help would be greatly
>appreciated.

Amir,

Although it's not well documented, TDBGrid descends from TCustomGrid, which  
does have a Row property.  Code like this works:
  TDrawGrid(DBGrid1).Row

  or

  TStringGrid(DBGrid1).Row

HTH,

Chris.
-------

Re:TDBGrid -- DBGridDrawColumnCell event


In article <8jah82$q...@bornews.borland.com>, aj...@galtney.com says...
Quote
> DBGridDrawColumnCell event has a COLUMN property but it doesn't have the ROW
> property.  Is it possible that I can get the ROW property also as to which
> row the grid is painting the data.  Any help would be greatly appreciated.

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
var
  nLine: integer;
begin
  nLine := Trunc(Rect.Top/(Rect.Bottom-Rect.Top+1));
  If not (gdFocused in State) Then Begin
    With DbGrid1, Canvas.Brush Do Begin
      If Odd(nLine) Then
        Color := clYellow
      Else
        Color := clWhite;
      DefaultDrawColumnCell(Rect,DataCol,Column,State);
    End;  { With }
  End;
end;

You'll also have to invalidate the TDBGrid's canvas after every record
position change.  You can do this in the TDBGrid's TDataSource
OnDataChange event handler.

procedure TForm1.MyTDataSourceDataChange(Sender: TObject; Field: TField);
begin
  DBGrid1.Invalidate;
end;

Hope this helps.
--
Jim Fitzgerald
EHS Innovators - CHEM Master? Division
JimF(at)Chem-Master(dot)Com

Re:TDBGrid -- DBGridDrawColumnCell event


seek [dbgrid and color and alternate] on http://www.deja.com/home_ps.shtml
Some solutions don't offer a correct color switching on indexed or filtered
tables.

Quote
Amir Ajani <aj...@galtney.com> wrote in message

news:8jah82$q063@bornews.borland.com...
Quote
> DBGridDrawColumnCell event has a COLUMN property but it doesn't have the
ROW
> property.  Is it possible that I can get the ROW property also as to which
> row the grid is painting the data.  Any help would be greatly appreciated.

> Thanks

Re:TDBGrid -- DBGridDrawColumnCell event


TDrawGrid(DBGrid1).Row

Quote
Jef Charlier wrote:
> seek [dbgrid and color and alternate] on http://www.deja.com/home_ps.shtml
> Some solutions don't offer a correct color switching on indexed or filtered
> tables.

> Amir Ajani <aj...@galtney.com> wrote in message
> news:8jah82$q063@bornews.borland.com...
> > DBGridDrawColumnCell event has a COLUMN property but it doesn't have the
> ROW
> > property.  Is it possible that I can get the ROW property also as to which
> > row the grid is painting the data.  Any help would be greatly appreciated.

> > Thanks

  gge.vcf
< 1K Download

Other Threads