Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
-
Thomas Speck
- Posts: 7
- Joined: Mon 08 Nov 2004 16:51
- Location: Karlsruhe
Post
by Thomas Speck » Tue 11 Jan 2005 12:08
Hello,
how can I change every second row the Color of the Cells of a TCRDBGrid ?
I have made the following:
Code: Select all
procedure TForm.CRDBGridDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
if (OraTable.RecNo mod 2) 1 then
begin
Canvas.Brush.Style := bsSolid;
Canvas.Brush.Color := clBlue;
end
else
begin
Canvas.Brush.Style := bsSolid;
Canvas.Brush.Color := clWhite;
end;
CRDBGrid.DefaultDrawColumnCell (Rect, DataCol, Column, State);
end;
This doesn't change anything in the Colors of the Cells of the Grid. How can I make it right ?
-
The_Rebel
Post
by The_Rebel » Tue 11 Jan 2005 14:21
maybe you should not tell delphi to override your drawed column by calling the default draw-routine after your code...
short C++ Sample of my drawing routine:
Code: Select all
TCRDBGrid *My = dynamic_cast (Sender);
if (My) {
TCanvas *pCanvas = My->Canvas;
//if (Canvas) ...
pCanvas->Font->Color = clBlack;
pCanvas->Brush->Color = clNavy;
pCanvas->FillRect( Rect );
pCanvas->TextOutA( Ract->Left, Rect->Top, ValueToShow.c_str() );
}
My = 0;
-
Alex
- Posts: 655
- Joined: Mon 08 Nov 2004 08:39
Post
by Alex » Tue 11 Jan 2005 14:45
You need to change Brush property of the TCRDBGrid object not the form
object, so you should change your code in this way:
Code: Select all
procedure TForm.CRDBGridDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
with CRDBGrid.Canvas.Brush do
if (OraTable.RecNo mod 2) 1 then
begin
Style := bsSolid;
Color := clBlue;
end
else
begin
Style := bsSolid;
Color := clWhite;
end;
CRDBGrid.DefaultDrawColumnCell (Rect, DataCol, Column, State);
end;
-
Guest
Post
by Guest » Tue 11 Jan 2005 14:50
Thank you for your Post, but your Solution doesn't work. After uncommenting DefaultDrawColumnCell nothing happens.
I will debug the Source tomorrow and will post my Solution then.
-
The_Rebel
Post
by The_Rebel » Tue 11 Jan 2005 14:52
sorry for my confusing post... (my delphi time is long ago)
i can also use the sender object to make your function accessable for different sender's, ther must be a dynamic_cast in delphi...
ps.: also the row attribute of the grid can be used for your mod 2
-
Thomas Speck
- Posts: 7
- Joined: Mon 08 Nov 2004 16:51
- Location: Karlsruhe
Post
by Thomas Speck » Tue 11 Jan 2005 15:00
It works now, I have forgotten to Set "DefaultDrawing" in Objectinspector to False.
Thank you for your Help !!