Board index » delphi » Highlighting current row in dbGrid

Highlighting current row in dbGrid

I want to be able to change the background color to clYellow for the
currently highlighted row in a dbGrid.  I'm aware of the RowSelect property
that does this, but the problem with RowSelect is when it's on I can't Edit.
So, what I want to do is handle this manually.  I'm currently using
OnDrawColumnCell to change colors of the font when a record contains certain
data, and that's no problem.  But, what I need to do to accomplish this is
highlight ONLY the currently selected row by making the Canvas.Color (I
assume) := clYellow.  How do I determine if it's drawing the row that
represents the currently selected record?

--
-= Jesse =-
http://www.msdlg.com
http://www.DaVinci-MIMS.com

 

Re:Highlighting current row in dbGrid


Hi Jesse,

And you checked this:

  TGridDrawState in the DrawDataCell ???

(with OwnerDraw = True)

HTH,
Cheers,
Ruben van Leeuwen

Quote
Jesse Castleberry wrote:
> I want to be able to change the background color to clYellow for the
> currently highlighted row in a dbGrid.  I'm aware of the RowSelect property
> that does this, but the problem with RowSelect is when it's on I can't Edit.
> So, what I want to do is handle this manually.  I'm currently using
> OnDrawColumnCell to change colors of the font when a record contains certain
> data, and that's no problem.  But, what I need to do to accomplish this is
> highlight ONLY the currently selected row by making the Canvas.Color (I
> assume) := clYellow.  How do I determine if it's drawing the row that
> represents the currently selected record?

> --
> -= Jesse =-
> http://www.msdlg.com
> http://www.DaVinci-MIMS.com

--
========================================================================
 I didn't fight my way to the top of the food chain to be a vegetarian.
========================================================================

Re:Highlighting current row in dbGrid


Unit  .....

Interface

Uses
......

Type
.......

  TMojCustomDBGrid = Class(TCustomDBGrid);
.......

Implementation
.......

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
  with TMojCustomDBGrid(Sender) do
    if DataLink.ActiveRecord = Row - 1 then
      Begin
       Canvas.Brush.Color := clYellow;
       Canvas.Font.Color := clBlack;
      End
    else
      Canvas.Brush.Color := clWhite;
  (Sender As TDBGrid).DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

.......

End.

Jesse Castleberry napisa3(a) w wiadomo?ci: ...

Quote
>I want to be able to change the background color to clYellow for the
>currently highlighted row in a dbGrid.  I'm aware of the RowSelect property
>that does this, but the problem with RowSelect is when it's on I can't
Edit.
>So, what I want to do is handle this manually.  I'm currently using
>OnDrawColumnCell to change colors of the font when a record contains
certain
>data, and that's no problem.  But, what I need to do to accomplish this is
>highlight ONLY the currently selected row by making the Canvas.Color (I
>assume) := clYellow.  How do I determine if it's drawing the row that
>represents the currently selected record?

>--
>-= Jesse =-
>http://www.msdlg.com
>http://www.DaVinci-MIMS.com

Other Threads