Re: Color row of DBGrid
- From: "FrancoJommi" <franco.jommi@xxxxxx>
- Date: Thu, 5 Jul 2007 10:22:43 +0200
Thanks, I'all surely try your code.
"Fons" <fonzzzNO@xxxxxxxxxxxxxxxxxxx> ha scritto nel messaggio
news:468b9397$0$323$e4fe514c@xxxxxxxxxxxxxxxxx
Try this:in
procedure TFormMain.StringGridDrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
DrawCell(ACol, ARow, Rect, State);
end;
procedure TFormMain.DrawCell(ACol, ARow: Integer; Rect: TRect; State:
TGridDrawState);
var
S : string;
TextTop, TextLeft : integer;
begin
S := Trim(StringGrid.Cells[ACol, ARow]);
TextTop := Rect.Top + (RectHeight(Rect) -
StringGrid.Canvas.TextHeight(S)) div 2;
TextLeft := Rect.Left + (RectWidth(Rect) -
StringGrid.Canvas.TextWidth(S)) div 2;
StringGrid.Canvas.Font.Color := clRed;
StringGrid.Canvas.Pen.Color := clRed;
StringGrid.Canvas.Brush.Color := clBtnFace;
StringGrid.Canvas.TextRect(Rect, TextLeft, TextTop, S);
end;
DrawCell is called for *every* cell (you can put the code directly in
StringGridDrawCell, but I always try to keep the code in the
event-handler as short as possible). But in DrawCell you can change the
Font, Pen or Brush color depending S (the text in the cell) or the
coordinates. You can draw lines, draw circles etc. But *do not* draw
outside the Rect. If you do you'll mess it up. Try drawing with random
colors. You'll see, this is not what you want. It'll give some
kaleidoscope when resizing the grid.
TextTop and TextLeft are only to center the text.
Hope this helps,
Fons.
Would you share what you have done or give guidance on how to do it ?
"Fons" <fonzzzNO@xxxxxxxxxxxxxxxxxxx> ha scritto nel messaggio
news:468ab710$0$336$e4fe514c@xxxxxxxxxxxxxxxxx
firstI change color of the 'current' record in a DBGrid using the
OnDrawColumnCell eventi with the following code:
if (gdFocused in State) or (gdSelected in State) then
begin
if BtnMod.Down then
MyDBGrid.Canvas.Brush.Color := clYellow
else
MyDBGrid.Options := DelegheDBGrid.Options + [dgRowSelect];
MyDBGrid.DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;
The problem I have is that it doesn't work exactly as I wanted. The
true.time I show the DBGrid no record are hilighted though dgRowSelect is
sinceClicking on the BtnMod the focused row is correctly painted in yellow,
recorddgRowSelect is true. But I need dgRowSelect to be false to edit the
and if it is set to false, the cells are not painted in yellow.I think you should do ALL the drawing of the cells in OnDrawColumnCell.
I have written a program with a grid with user-chosen colors, crosses
colored cells etc. Most of the standard drawing, not different from aOptions.
standard grid is simple; that's not too much work.
I think it doesn't work with just changing the Brush.Color and the
Thanks in advance for any suggestions.Fons.
.
- References:
- Re: Color row of DBGrid
- From: Fons
- Re: Color row of DBGrid
- From: FrancoJommi
- Re: Color row of DBGrid
- From: Fons
- Re: Color row of DBGrid
- Prev by Date: Re: Working with windows handles
- Next by Date: Re: Color row of DBGrid
- Previous by thread: Re: Color row of DBGrid
- Next by thread: Re: Color row of DBGrid
- Index(es):
Relevant Pages
|