• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

DBGrid Question

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
HotRod40
Asked:
HotRod40
1 Solution
 
Zip58Commented:
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
 
NoturnoCommented:
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
 
LukA_YJKCommented:
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
 
ILECommented:

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now