Solved

color in a row of a dbgrid

Posted on 1998-04-18
4
399 Views
Last Modified: 2010-04-06
we are using dbgrid's and we need paint diferent rows with different colors how can I do it ?
0
Comment
Question by:jaldana
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
inter earned 50 total points
ID: 1335011
Hi,
The simples way is to obtain the  RxLib Delphi component package and use their RXDBgrid(The package contains dozens of very useful components). It has several other capabilites over DBGrid and is FREE. You can download it from:

  http://rx.demo.ru/files/index.html or
direcly
 http://rx.demo.ru/files/rxlib240.zip

USE IT, YOU WILL BE SATISFIED

Regards,
Igor
0
 
LVL 5

Expert Comment

by:julio011597
ID: 1335012
What about an OwnerDraw'ed DBGrid?
It is not that hard, IMO.
0
 
LVL 5

Expert Comment

by:inter
ID: 1335013
Fine,
Thats one way, however, can not simply compete with RxLib(it takes time I mean). Any way julio is right.
Regards,
Inter
0
 

Expert Comment

by:schappel
ID: 1335014
Sure the simplest way of doing something is to use what somebody
else has written, but that dowsn't teach you anything.

I would suggest that you use an OwnerDrawGrid.  All you have to
do is the following:
 Change the DefaultDrawing property of the DBGrid to False

 Add Some code to the OnDrawColumnCell (*Use this one as
 OnDrawDataCell is supposed to obsolete *)
 e.g.
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if Table1.FieldByName('ItemsTotal').Value > 10000 then
  begin
    // Change the line to be bold for lines with above ^^
    DBGrid1.Canvas.Font.Style := [fsBold];  
    if Column.FieldName = 'ItemsTotal' then
      // Change the Color to red for the ItemsTotalColumn if
      // the prior condition is met
      DBGrid1.Canvas.Font.color := clRed;
  end;

  // Call the default drawing now as all we have done is changed
  // the color of thins.  If we wanted to draw in different
  // styles like 3D tehn we would have to handle that aswell
  DBGrid1.DefaultDrawColumnCell( Rect, DataCol, Column, State );
end;


hope this helps

Scott
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now