Solved

color in a row of a dbgrid

Posted on 1998-04-18
4
398 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
Comment Utility
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
Comment Utility
What about an OwnerDraw'ed DBGrid?
It is not that hard, IMO.
0
 
LVL 5

Expert Comment

by:inter
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

18 Experts available now in Live!

Get 1:1 Help Now