Wayne Niddery [TeamB] Guest
|
Posted: Fri Jan 09, 2004 10:56 pm Post subject: Re: highlight dbgrid rows |
|
|
Nick Iorio wrote:
| Quote: | I want to selectively highlight - set background to a color -
specific rows in a dbgrid based on the value of a column in the grid.
I'm using Delphi 5. TIA - nick
|
The following example will work on any table with a 'salary' field such as
the employee.db table in DBDEMOS.
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Table1.FieldByName('salary').AsFloat > 40000 then
DBGrid1.Canvas.Brush.Color := clYellow
else
DBGrid1.Canvas.Brush.Color := clWindow;
// override for selected
if gdSelected in State then
DBGrid1.Canvas.Brush.Color := clHighlight;
DbGrid1.DefaultDrawColumnCell(Rect,DataCol, Column, State);
end;
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"It is error alone which needs the support of government. Truth can
stand by itself." - Thomas Jefferson
|
|