DBGrid Problem with odd even rows

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

  • : 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

    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.
  • it works fine in paradox table but when i use it in interbase table it does not work? how can this be :-)
  • i think the problem is at the [RowNo := Query1.RecNo;] because if i use a paradox Table the value of RowNo is morethan 0 but if i use an InterBase Table the Value of RowNo is always -1. can any one please help me. im so desparate. thanks

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories