Delphi在DBGridEh改变选中行颜色


运行效果:选中行变为蓝色
步骤1:设置dbgrid的options的dgrowselect为true.
步骤2:在dbgrid的ondrawcolumncell事件里面写上:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if gdSelected  in state then
    dbgrid1.Canvas.Brush.Color:=clblue;
     dbgrid1.DefaultDrawColumnCell(rect,datacol,column,state);
end;

 

//定义网格线的颜色:
DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
with (Sender as TDBGrid).Canvas do //画 cell 的边框
begin
Pen.Color := $00ff0000; //定义画笔颜色(蓝色)
MoveTo(Rect.Left, Rect.Bottom); //画笔定位
LineTo(Rect.Right, Rect.Bottom); //画蓝色的横线
Pen.Color := $0000ff00; //定义画笔颜色(绿色)
MoveTo(Rect.Right, Rect.Top); //画笔定位
LineTo(Rect.Right, Rect.Bottom); //画绿色的竖线
end;
end;

 

//隔行改变网格背景色:
if Query1.RecNo mod 2 = 0 then
(Sender as TDBGrid).Canvas.Brush.Color := clInfoBk //定义背景颜色
else
(Sender as TDBGrid).Canvas.Brush.Color := RGB(191, 255, 223); //定义背景颜色

出处: http://www.cnblogs.com/zhengwei0113/p/4366353.html

猜你喜欢

转载自blog.csdn.net/Michael__mai/article/details/50776940