?
Solved

dbgrid with different colours in rows

Posted on 2003-03-02
5
Medium Priority
?
659 Views
Last Modified: 2012-06-27
This surely is an easy question, but I can't manage it:
How can I make that in a dbgrid a row has a differnt colour depending of the value in a recordfield of that row.
For example:
If the fieldvalue of column[5] is null, all the entries in that row must be drawn in red ?
Thank you.
0
Comment
Question by:SCHUCla74
[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
5 Comments
 
LVL 3

Expert Comment

by:LukA_YJK
ID: 8051171
0
 
LVL 7

Expert Comment

by:Motaz
ID: 8051214
Put this code in dbGrid OnDrawDataCell:

procedure TfmMain.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
  Field: TField; State: TGridDrawState);
begin

  if dbGrid1.DataSet.Fields[4].IsNull then
    dbGrid1.Canvas.Brush.Color:= clRed
  else
    dbGrid1.Canvas.Brush.Color:= clWhite
     
  dbGrid1.Canvas.TextRect(Rect, Rect.Left,  Rect.Top, Field.AsString);
 
end;
0
 

Accepted Solution

by:
da-vinci earned 200 total points
ID: 8051232
OnDrawDataCell is not recommended anymore, this is what Borland says: "OnDrawDataCell is obsolete and included for backward compatibility. Instead, write an OnDrawColumnCell event handler."

procedure TMainForm.DBGrid1DrawColumnCell(Sender: TObject;
    const Rect: TRect; DataCol: Integer; Column: TColumn;
    State: TGridDrawState);
begin
    if DataSource1.DataSet.Fields[5].IsNull then
        DbGrid1.Canvas.Brush.Color := clRed;
    DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

If you want you can also just mark that cell as red.
0
 

Expert Comment

by:da-vinci
ID: 8051237
OnDrawDataCell is not recommended anymore, this is what Borland says: "OnDrawDataCell is obsolete and included for backward compatibility. Instead, write an OnDrawColumnCell event handler."

procedure TMainForm.DBGrid1DrawColumnCell(Sender: TObject;
    const Rect: TRect; DataCol: Integer; Column: TColumn;
    State: TGridDrawState);
begin
    if DataSource1.DataSet.Fields[5].IsNull then
        DbGrid1.Canvas.Brush.Color := clRed;
    DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

If you want you can also just mark that cell as red.
0
 

Author Comment

by:SCHUCla74
ID: 8051556
It works !!!
Thank you all.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month12 days, 5 hours left to enroll

752 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