clyde99
asked on
Change color of a grid row
Using Delphi 3 it is quite easy to change the color of a column but I can't see how to changed the color of a row (or even just a single cell, for that matter) . My main interest is a dbgrid but I guess the same principle applies to a stringgrid.
For example I have a customer DBgrid that I would like to highlight all customers over 30 days due, in the color red
For example I have a customer DBgrid that I would like to highlight all customers over 30 days due, in the color red
btw.
for example2 set the defaultdrawing to false in the object inspector.
for example2 set the defaultdrawing to false in the object inspector.
ASKER
The above code for example 1 only seems to work when I select a cell with the mouse. How do I get the the required cells/rows to change color when the grid is initially displayed?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Barry,
Thankyou.
That was EXACTLY what I was trying to do
Clyde
Thankyou.
That was EXACTLY what I was trying to do
Clyde
good to hear & :-))
merry xmas
merry xmas
i give you 2 examples of drawing the grids(yes i have the samples in stringgrids but also applies to dbgrids :-)
example 1:
procedure TForm1.StringGrid1DrawCell
Rect: TRect; State: TGridDrawState);
var
FocusedRect : TRect;
begin
FocusedRect := Rect;
StringGrid1.Canvas.Font.Co
StringGrid1.Canvas.Pen.Col
StringGrid1.Canvas.Pen.Wid
if ( gdFocused in State ) then begin
StringGrid1.Canvas.Font.St
StringGrid1.Canvas.Font.Co
StringGrid1.Canvas.Brush.C
end
else
StringGrid1.Canvas.Font.St
InflateRect(FocusedRect, -2, -2);
StringGrid1.Canvas.FillRec
if ( gdSelected in State ) then
StringGrid1.Canvas.TextOut
StringGrid1.Canvas.TextOut
end;
example 2:
procedure TForm1.StringGrid1DrawCell
Rect: TRect; State: TGridDrawState);
var
checked: boolean;
oldbrush: integer;
oldpen: tpen;
begin
with stringgrid1.canvas,rect do
begin
oldbrush:=brush.color;
brush.color:=clyellow;
oldpen:=pen;
pen.Width:=2;
pen.color:=clred;
moveto(left+1,top+2);
polygon([point(left,top),
point(left,bottom),
point(right,bottom),
point(right,top),
point(left,top)]);
checked:=boolean(stringgri
if checked then
begin
brush.Color := clblue;
polygon([point(left,top),
point(left,bottom),
point(right,bottom),
point(right,top),
point(left,top)]);
end;
brush.color:=oldbrush;
textout(left+17,top+4,stri
pen:=oldpen;
end;
end;
procedure TForm1.StringGrid1MouseDow
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
r,c: integer;
checked: boolean;
begin
with stringgrid1 do
begin
mousetocell(x,y,c,r);
checked:=(longint(objects[
if checked then objects[c,r]:=pointer(0) else objects[c,r]:=pointer(1);
end;
end;
should give some ideas
Regards Barry