?
Solved

DBGrid Question

Posted on 2003-03-22
4
Medium Priority
?
302 Views
Last Modified: 2010-04-04
Hi,

Can anyone tell me how I can highlight or use a different colour on certain rows in a dbgrid.
I will loop through the grid and on a specific entry in a column, highlight that row in a certain
colour then move on to the next row.

Any help would be great,
Thanks
0
Comment
Question by:HotRod40
[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
4 Comments
 
LVL 2

Expert Comment

by:Zip58
ID: 8186295
Hi HotRod40

mabey you can try this freeware componnent with source

http://www.scalabium.com/smdbgrid.htm

Ps. It have a lot more options of the original dbgrid

Regards

Zip58
0
 
LVL 1

Accepted Solution

by:
Noturno earned 225 total points
ID: 8186359
You can use the OnDrawColumnCell event of the DBGrid to make this. For example, if you want to chage the font color when a boolean field of your table is true:

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if Table1.FieldByName('Canceled').AsBoolean Then
    DBGrid1.Canvas.Font.Color := clRed;
  DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

In the example, the DefaultDrawColumnCell method draws the cell using the color (clRed) specified by you when the Field 'Canceled' is true. The other records will be "drawn" (for give me for my terrible english, i don't know the correct word now) with the color defined previously.

Regards

Name: Gleyson Melo -> Nick: Noturno
Country: Brazil -> State: Pará
0
 
LVL 3

Expert Comment

by:LukA_YJK
ID: 8186494
There were such a question:
How to make a difference DBGrid color for each record
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20339601.html
0
 
LVL 3

Expert Comment

by:ILE
ID: 8187724

if u wona change color based on a row value for example data something like this


if table1.fieldbyname('data')=15 then
begin
dbgrid1.canvas.font.color:=clred; {font} dbgrid1.canvas.brush.color:=clblack; {background}

{this part is for allign data  }
if field.datatype in [ftcurrency,ftfloat] then
str(field.asfloat:13:2,s) else s:=field.text;
dbgrid1.canvas.textrect(rect,rect.left,rect.top,s);

end;


baseg on colmun for examle difrent color on colmun Name


if field.dysplaylabel='Name' then
begin
dbgrid1.canvas.font.color:=clred; {font} dbgrid1.canvas.brush.color:=clblack; {background}

{this part is for allign data  }
if field.datatype in [ftcurrency,ftfloat] then
str(field.asfloat:13:2,s) else s:=field.text;
dbgrid1.canvas.textrect(rect,rect.left,rect.top,s);

end;



0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month10 days, 9 hours left to enroll

765 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