自己要学会搜索
DBGrid中的行以颜色间隔的方式显示
自己是个Delphi迷,但许多技巧都是从网上拿来之,却没给大家奉献点啥子,甚是惭愧!只
有一点小东东略表心意:
笔者想把DBGrid中的行以颜色间隔的方式显示出来,方法是:
procedure DrawGrid(Grid:TDBGrid;const Rect: TRect;
DataCol: Integer;
Column: TColumn;
State: TGridDrawState);
begin
if odd(Grid.DataSource.DataSet.RecNo) then
//奇偶行判断
begin
Grid.Canvas.Font.Color:=clblack;
Grid.Canvas.Brush.color:=clwhite;
end
else
begin
Grid.Canvas.Font.Color:=clblack;
Grid.Canvas.Brush.color:=clcream;
end;
if Grid.SelectedRows.CurrentRowSelected then
//dgRowSelect和dgMultiSelect都为真时有效
begin
Grid.Canvas.Font.Size:=12;
Grid.Canvas.Font.Style:=[fsBold];
Grid.Canvas.Font.Color:=clwhite;
Grid.Canvas.Brush.color:=clNavy;
end;
Grid.DefaultDrawColumnCell(rect,datacol,column,state);
end;
在OnDrawColumnCell事件中放入DrawGrid((sender as TDBGrid),Rect,DataCol,Column,State)就大功告成了。谢谢无偿使用!