jaldana
asked on
color in a row of a dbgrid
we are using dbgrid's and we need paint diferent rows with different colors how can I do it ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Fine,
Thats one way, however, can not simply compete with RxLib(it takes time I mean). Any way julio is right.
Regards,
Inter
Thats one way, however, can not simply compete with RxLib(it takes time I mean). Any way julio is right.
Regards,
Inter
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.DBGrid1DrawColumnCe ll(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Table1.FieldByName('ItemsT otal').Val ue > 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.DefaultDrawColumnC ell( Rect, DataCol, Column, State );
end;
hope this helps
Scott
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.DBGrid1DrawColumnCe
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Table1.FieldByName('ItemsT
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.DefaultDrawColumnC
end;
hope this helps
Scott
It is not that hard, IMO.