设置DBGrid当前行的颜色

lance 2008-08-23 12:02:12
http://www.cnblogs.com/lance2088/archive/2008/08/21/1272976.html

定义个子类MyDBGrid继承TDBGrid,以提供访问父类保护成员的接口。
type
MyDBGrid=class(TDBGrid)
private

public
function GetRow:integer;
function IsCurrent:boolean;
end;





function MyDBGrid.GetRow: integer;
begin
result:=row;
end;

function MyDBGrid.IsCurrent: boolean;
begin
result:=(DataLink.ActiveRecord=row-1);
end;



判断是否是当前行。

type
TGlobal=class

class function IsCurrentRow(AMyDBGrid:MyDBGrid):boolean;

end;


class function TGlobal.IsCurrentRow(AMyDBGrid: MyDBGrid): boolean;
begin
result:=AMyDBGrid.IsCurrent;
end;



在DrawColumnCell事件中。



procedure TFormMain.MyDBGridDrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if TGlobal.IsCurrentRow(MYDBGrid(Sender))

begin
(Sender as TDBGrid).Canvas.Brush.Color :=$000080FF;

end
else
begin
if (Sender as TDBGrid).DataSource.DataSet.RecNo mod 2 =0 then
(Sender as TDBGrid).Canvas.Brush.Color :=rgb(246,246,246); //$00F3F3F3; //定义背景颜色
end;
(Sender as TDBGrid).DefaultDrawColumnCell(Rect,DataCol,Column,State);

end;



效果:
...全文
231 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
lance 2008-08-26
  • 打赏
  • 举报
回复
你不如直接回复 www.google.com
lance 2008-08-26
  • 打赏
  • 举报
回复
你不如直接回复 www.google.com

在DrawColumnCell事件里 如何能知道当前画的是哪一行?

lw549 2008-08-26
  • 打赏
  • 举报
回复
我不想继续回复这个帖子了,很无聊。

http://www.google.com/search?client=opera&rls=en&q=DrawColumnCell&sourceid=opera&ie=utf-8&oe=utf-8
lance 2008-08-26
  • 打赏
  • 举报
回复
楼上的给搜一把看看。

我上面给出的办法不是设置行选择,当失去焦点后还是显示设置的颜色。
lance 2008-08-26
  • 打赏
  • 举报
回复
呵呵。在DrawColumnCell事件中如何知道当前画的是哪行?
jin20000 2008-08-25
  • 打赏
  • 举报
回复
哦了,还系顶一下!~
i_am_different 2008-08-25
  • 打赏
  • 举报
回复
顶你
lw549 2008-08-25
  • 打赏
  • 举报
回复
网上一搜一大把。
lance 2008-08-23
  • 打赏
  • 举报
回复
如果有源代码,跟进去看看。
lyguo 2008-08-23
  • 打赏
  • 举报
回复
我用DBGRIDEH
用到(Sender as TDBGridEH).DefaultDrawColumnCell(Rect,DataCol,Column,State); 这个时出错,提示类型不。。。
lance 2008-08-23
  • 打赏
  • 举报
回复
很多人问如何设置DBGrid当前行的颜色,这是一个解决的办法。
youcunzai 2008-08-23
  • 打赏
  • 举报
回复
"产品"展示?
lyguo 2008-08-23
  • 打赏
  • 举报
回复
你想问什么?
shuihan20e 2008-08-23
  • 打赏
  • 举报
回复
?

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧