Solved

row color in a DbGrid

Posted on 2002-05-03
3
277 Views
Last Modified: 2010-04-04
How can I put an specific color in a selected row in a DBGRid?

thanks in advance.

sincerly

  AFM.

0
Comment
Question by:AngelFireMateo
3 Comments
 
LVL 4

Accepted Solution

by:
nestorua earned 50 total points
ID: 6988712
HI,
Paste you my comment to Spk2000ar for sthe similar question.
1.Set the DefaultDrawing property of your DBGrid to True.
In OnDrawColumnCell event write the following:

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column:
TColumn; State: TGridDrawState);
var OldBrush, OldFont: TColor;
begin
with Sender as TDBGrid do
 with Canvas do
  begin
    OldBrush:=Brush.Color;
     OldFont:=Font.Color;
//here goes your condition for highlighting:
  if (DataSource.DataSet[YourFieldName]=0)
   then
    begin
     if gdSelected in State
      then
       begin
        Brush.Color:=clRed;
         Font.Color:=clAqua;
       end
      else
       begin
        Brush.Color:=$00DDDFFF;
         Font.Color:=clBlack;
       end;
      end;
//
   DefaultDrawColumnCell(Rect, DataCol, Column, State);
//
    Brush.Color:=OldBrush;
     Font.Color:=OldFont;
end;

Sincerely,
Nestorua.  
0
 
LVL 2

Expert Comment

by:freshman3k
ID: 6989251
Hello,

Also, This Borland Community Article has a good explanation.

http://community.borland.com/article/0,1410,20845,00.html
0
 
LVL 1

Expert Comment

by:pnh73
ID: 9004590
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept answer from nestorua

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
FMX StringGrid1->Canvas->FillRect Problem 3 170
Tembedded WB animatid gifs not animated on some pcs 2 84
Base1 Encode/Decode 3 81
Delphi and Access based Enumeration 9 70
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question