?
Solved

row color in a DbGrid

Posted on 2002-05-03
3
Medium Priority
?
281 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 200 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

801 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