Board index » delphi » Highlighting rows in TDBGrid D5

Highlighting rows in TDBGrid D5

I have a problem that's driving me nuts.

What I am attempting to do is highlight lines in a DBGrid when the record
has a match in another table.  The data source for the grid is a query
against an ODBC/SQL database.  The match table is a local Paradox table.  I
have added code to the grid drawing event (OnDrawDataCell) to change the
canvas color if there's a match.

For example:

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);

begin
  if (ActSelectActive.checked)        // If selection is allowed
    and (state = []) then begin
    if dataCol = 0 then                        // If the first column of the
grid
      LineSelected :=
TblList.FindKey([QryWs.FieldByName('User_No').AsString]);

    If LineSelected then
     begin
      Column.color := clBlue;
      Column.font.color := clWhite;
     end
    else
     begin
      Column.color := EdtSurname.color;
      Column.font.color := EdtSurname.font.color;
     end;  { if  }
  end;  { if }

  DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State)

end;

The problem I have is that no matter what I do, it is the following line
that is displayed with the reversed colors, not the selected line.  The
other problem is that the action of looking up the Paradox table (which I
only perform on the first column of the line) seems to cause the grid to
continuously refresh.

Any help would be appreciated.

 

Re:Highlighting rows in TDBGrid D5


On Mon, 24 Jan 2000 21:22:38 +1100, "Stephen Corbett"

Quote
<corb...@corbtech.com.au> wrote:
>I have a problem that's driving me nuts.

>What I am attempting to do is highlight lines in a DBGrid when the record
>has a match in another table.  The data source for the grid is a query
>against an ODBC/SQL database.  The match table is a local Paradox table.  I
>have added code to the grid drawing event (OnDrawDataCell) to change the
>canvas color if there's a match.

Use DBGrid1.Canvas.Brush.Color instead of Column.Color and
DBGrid1.Canvas.Font.Color instead of Column.Font.Color.

Quote
>The other problem is that the action of looking up the Paradox table (which I
>only perform on the first column of the line) seems to cause the grid to
>continuously refresh.

This should only be possible if there is an event on this Paradox
table that affects the underlying DataSet of the grid.

Jan

Re:Highlighting rows in TDBGrid D5


Thanks Jan, that worked great!!  The problem of the refresh "disappeared" of
its own accord.  Could it have been something to do with not changing the
columns property??

Steve  ;-}

Re:Highlighting rows in TDBGrid D5


On Thu, 27 Jan 2000 19:44:04 +1100, "Stephen Corbett"

Quote
<corb...@corbtech.com.au> wrote:
>Thanks Jan, that worked great!!  The problem of the refresh "disappeared" of
>its own accord.  Could it have been something to do with not changing the
>columns property??

If the refresh you are talking about is the repainting of the grid,
then yes, setting TColumn.Color invalidates the complete column and
hence, causes a (partial) repaint of the grid.

Jan

Other Threads