komputer
asked on
coloring dbgrid rows
hi,
i would like to color dbgrid rows if row count is odd, row color is red else blue.
i tried this,
procedure TForm1.DBGrid1DrawColumnCe ll(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if (query1.RecNo mod 2) = 1 then
DBGrid1.Canvas.Brush.Color := clRed
else
DBGrid1.Canvas.Brush.Color := clBlue;
DBGrid1.DefaultDrawColumnC ell(Rect, DataCol, Column, State);
end;
but it doesnt work, cause query1.RecNo is always -1.
if you help me, i will pleased.
thanks...
i would like to color dbgrid rows if row count is odd, row color is red else blue.
i tried this,
procedure TForm1.DBGrid1DrawColumnCe
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if (query1.RecNo mod 2) = 1 then
DBGrid1.Canvas.Brush.Color
else
DBGrid1.Canvas.Brush.Color
DBGrid1.DefaultDrawColumnC
end;
but it doesnt work, cause query1.RecNo is always -1.
if you help me, i will pleased.
thanks...
ASKER
but i cant DBGrid1.DataSource.DataSet .ActiveRec ord property,
given error message 'undeclared identifier: 'ActiveRecord'
given error message 'undeclared identifier: 'ActiveRecord'
>but it doesnt work, cause query1.RecNo is always -1.
after the open-method, or in the afteropen-event use
query1.fetchall;
this will edjust the recno-property
attention: this will cause a performance leak after open a huge dataset
meikl ;-)
after the open-method, or in the afteropen-event use
query1.fetchall;
this will edjust the recno-property
attention: this will cause a performance leak after open a huge dataset
meikl ;-)
ASKER
to kretzschmar
i tried but it doesnt work. it stills return -1 as RecNo
i tried but it doesnt work. it stills return -1 as RecNo
well, in this case use additional the last-method like
query1.fetchall;
query1.last;
hope thats it
meikl ;-)
query1.fetchall;
query1.last;
hope thats it
meikl ;-)
ASKER
to kretzschmar again
i tried but it doesnt work. it still returns -1 as RecNo
i tried but it doesnt work. it still returns -1 as RecNo
well, then you can't use the recno for this
(the correct entry depends on the database u use)
(the correct entry depends on the database u use)
I tested the following with both a TTable and TQuery dataset linked to the datasource. Both works fine.
procedure TForm1.DBGrid1DrawColumnCe ll(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Odd(DbGrid1.DataSource.Dat aSet.RecNo )
then DBGRID1.Canvas.Brush.Color := clBlue
else DBGRID1.Canvas.Brush.Color := clRed;
DBGRID1.DefaultDrawColumnC ell(Rect, DataCol, Column, State);
Invalidate;
end;
What dataset are you using? What type query?
procedure TForm1.DBGrid1DrawColumnCe
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Odd(DbGrid1.DataSource.Dat
then DBGRID1.Canvas.Brush.Color
else DBGRID1.Canvas.Brush.Color
DBGRID1.DefaultDrawColumnC
Invalidate;
end;
What dataset are you using? What type query?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i think the problem is my database (ms sql server) doesnt hve recno property.
EddieShipman's solution is ok.
thaks guys...
EddieShipman's solution is ok.
thaks guys...
query1.RecNo
DBGrid1.DataSource.DataSet