i want to color my dbgrid in odd and even rows but it dont work.. my code is... procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
var
test1: Real;
RowNo, farbe: Integer;
begin
with (Sender as TDBGrid) do
begin
if (gdSelected in State) then
begin
Canvas.Brush.Color := clblue;
end
else
begin
rowno := Query1.RecNo;
test1 := (RowNo / 2) - trunc(RowNo / 2);
if test1 = 0 then
begin
farbe := clWhite
end
else
begin
farbe := clYellow;
end;
Canvas.Brush.Color := farbe;
Canvas.Font.Color := clBlack;
end;
Canvas.FillRect(Rect);
Canvas.TextOut(Rect.Left + 2, Rect.Top + 1, Column.Field.AsString);
end
end; i am using Interbase table with SQL command. thanks
Comments
: code is... procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
: const Rect: TRect; DataCol: Integer; Column: TColumn;
: State: TGridDrawState);
: var
: test1: Real;
: RowNo, farbe: Integer;
: begin
: with (Sender as TDBGrid) do
: begin
: if (gdSelected in State) then
: begin
: Canvas.Brush.Color := clblue;
: end
: else
: begin
: rowno := Query1.RecNo;
: test1 := (RowNo / 2) - trunc(RowNo / 2);
: if test1 = 0 then
: begin
: farbe := clWhite
: end
: else
: begin
: farbe := clYellow;
: end;
: Canvas.Brush.Color := farbe;
: Canvas.Font.Color := clBlack;
: end;
: Canvas.FillRect(Rect);
: Canvas.TextOut(Rect.Left + 2, Rect.Top + 1, Column.Field.AsString);
: end
: end; i am using Interbase table with SQL command. thanks
Tests for odd/even can be coded much easier:
[code]
if (RowNo mod 2 = 0) then
begin
// Even
end else begin
// Odd
end;
[/code]
The x [b]mod[/b]ulo y gives the remainder of the division x/y.