Solved

row color in a DbGrid

Posted on 2002-05-03
3
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

737 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