Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > DB-Aware

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 10-26-2004, 08:33 AM
xing3ds xing3ds is offline
Junior Member
 
Join Date: Sep 2004
Posts: 19
Default Coloring TDBGrid

Hi All,
How to color specific row in TDBGRID? lets says I wanted to color a row based on one of the column data.
so, if the column data is 'A', it should make that specific rows to have different colour compare to other rows.

PS: I need a quick reply for this one, Thanks a lot. I will definetly accept it as an answer if it works. ^__^

Many Thanks.
Reply With Quote
  #2  
Old 10-26-2004, 08:49 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: Coloring TDBGrid

Try something like this:

Code:
// Write an OnDrawColumnCell handler like this:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if (DBGrid1.Datasource.Dataset.Fields[DataCol].Value = RequiredValue) and 
     (not (gdSselected in State)) then
  begin
      DBGrid1.Canvas.Brush.Color :=$00FFC8C1;
  end;
  DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

// set the afterscroll for your dataset like this:
// I used a TADOQuery to test...
procedure TForm1.ADOQuery1AfterScroll(DataSet: TDataSet);
begin
  DBGrid1.Repaint;
end;
MrBaseball34
Hook'Em Horns!
Reply With Quote
  #3  
Old 10-26-2004, 08:50 AM
AceOmega AceOmega is offline
Senior Member
 
Join Date: Sep 2004
Posts: 2,393
Default RE: Coloring TDBGrid

From Delphi help on TDBGRID Canvas property....

Code:
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState);
var
  index: integer;
begin
  with Sender as TDBGrid do
  begin
    Canvas.Brush.Color := clBackGround;
    Canvas.FillRect(Rect);
  end;

end;
Sorry, I did not have time to clean it up for you.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:29 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.