http://www.oschina.net/code/snippet_54100_1102
Developer Express的cxGrid控件是一个相当有特色的数据栅格组件,支持自动分组、卡片式显示、和像Excel那样的过滤功能等。不过它在多选区时的显示 方式却不太友善,对于我这样还有点追求的人来说肯定是不会满足的了,于是通过它的OnDrawColumnHeader事件和 OnDrawIndicatorCell事件把它变成像Excel那样以高亮显示行号列标。

PS:我平时是用来显示数据的,没有考虑编辑状态;为了说明效果,cxGrid使用DBTableView并设成允许多选和选区方式(在OptionsView里有设)。

OnDrawColumnHeader事件源码如下:

 
 
procedure TfrmAccount.cxtvMasterCustomDrawColumnHeader(
Sender: TcxGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxGridColumnHeaderViewInfo; var ADone: Boolean);
var
AButtonState: TcxButtonState;
ARect: TRect;
begin
if AViewInfo.Column.Selected then begin
AButtonState := cxbsHot;
ARect := AViewInfo.Bounds;
Sender.LookAndFeelPainter.DrawHeader(ACanvas, ARect, AViewInfo.TextAreaBounds
, [], cxBordersAll, AButtonState, AViewInfo.Column.HeaderAlignmentHorz
, AViewInfo.Column.HeaderAlignmentVert, False, False
, AViewInfo.Column.Caption, ACanvas.Font, Sender.Styles.Selection.TextColor
, Sender.Styles.Selection.Color);
{========================================================================
DESIGN BY : 彭国辉
DATE: 2007-03-02
SITE: http://kacarton.yeah.net/
BLOG: http://blog.csdn.net/nhconch
EMAIL: kacarton#sohu.com
文章为作者原创,转载前请先与本人联系,转载请注明文章出处、保留作者信息,谢谢支持!
=========================================================================}
ARect.Left := ARect.Right - ;
ARect.Right := ARect.Right - ;
InflateRect(ARect, -, -);
if AViewInfo.Column.Options.Filtering then begin
Sender.LookAndFeelPainter.DrawFilterDropDownButton(ACanvas, ARect
, cxbsNormal, AViewInfo.Column.Filtered);
OffsetRect(ARect, -, );
end;
if AViewInfo.Column.SortIndex <> - then
Sender.LookAndFeelPainter.DrawSortingMark(ACanvas, ARect
, AViewInfo.Column.SortOrder=soAscending);
ADone := true;
end;
end; OnDrawIndicatorCell事件源码如下:
procedure TfrmAccount.cxtvMasterCustomDrawIndicatorCell(
Sender: TcxGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
var
AButtonState: TcxButtonState;
clFont, clBrush: TColor;
begin
if not (AViewInfo is TcxGridIndicatorRowItemViewInfo) then Exit; if TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Selected then begin
AButtonState := cxbsHot;
if Sender.LookAndFeelPainter.LookAndFeelStyle = lfsOffice11 then begin
clFont := ACanvas.Font.Color;
clBrush := ACanvas.Brush.Color;
end else begin
clFont := Sender.Styles.Selection.TextColor;
clBrush := Sender.Styles.Selection.Color;
end;
end else begin
AButtonState := cxbsNormal;
clFont := ACanvas.Font.Color;
clBrush := ACanvas.Brush.Color;
end;
Sender.LookAndFeelPainter.DrawHeader(ACanvas, AViewInfo.ContentBounds,
AViewInfo.ContentBounds, [], [bLeft, bRight, bBottom], AButtonState, taCenter
, vaCenter, False, False, IntToStr(TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Index + )
, ACanvas.Font, clFont, clBrush);
ADone := True;
end;

让cxGrid像Excel那样高亮显示选区的行号列标的更多相关文章

  1. vim 配置文件 ,高亮+自动缩进+行号+折叠+优化

    vim 配置文件 ,高亮+自动缩进+行号+折叠+优化 将一下代码copy到 用户目录下 新建文件为  .vimrc保存即可生效: 如果想所有用户生效 请修改 /etc/vimrc (建议先cp一份)& ...

  2. linux vim 配置文件(高亮+自动缩进+行号+折叠+优化)

    点评:将一下代码copy到 用户目录下 新建文件为 .vimrc保存即可生效 如果想所有用户生效 请修改 /etc/vimrc (建议先cp一份)"===================== ...

  3. vim配置 高亮+自动缩进+行号+折叠+优化

    一:修改 .vimrc即可 二: set nocompatible " 关闭 vi 兼容模式syntax on " 自动语法高亮colorscheme molokai " ...

  4. vim 配置文件.vimrc,高亮+自动缩进+行号+折叠+优化

    将一下代码copy到 用户目录下 新建文件为  .vimrc保存即可生效: 如果想所有用户生效 请修改 /etc/vimrc (建议先cp一份)"====================== ...

  5. cxGrid 显示行号及行号列列名

    cxGrid默认不显示行号,但是可以通过cxGrid1DBTableView1CustomDrawIndicatorCell事件来重绘行号 选中cxGrid1DBTableView1,在OnCusto ...

  6. 【转】vim 配置文件 ,高亮+自动缩进+行号+折叠+优化

    将一下代码copy到 用户目录下 新建文件为  .vimrc保存即可生效: 如果想所有用户生效 请修改 /etc/vimrc (建议先cp一份) "===================== ...

  7. C#操作EXCEL常见操作集合(行高,列宽,合并单元格,单元格边框线)

    private _Workbook _workBook = null; private Worksheet _workSheet = null; private Excel.Application _ ...

  8. C#/VB.NET 获取Excel中图片所在的行、列坐标位置

    本文以C#和vb.net代码示例展示如何来获取Excel工作表中图片的坐标位置.这里的坐标位置是指图片左上角顶点所在的单元格行和列位置,横坐标即顶点所在的第几列.纵坐标即顶点所在的第几行.下面是获取图 ...

  9. 在EXCEL中如何同时冻结行与列?

    鼠标所在的单元格的位置 ,决定了你冻结的行和列.如: 冻结第一行与第一列, 只需要将鼠标置于单元格在第二列,第二行. 点击冻结

随机推荐

  1. Autopilot Pattern Redis

    https://github.com/autopilotpattern/redis Architecture 正在运行的群集包括以下组件: Redis :我们使用的是Redis 3.2. Redis ...

  2. lrzsz的安装与配置

    1)下载http://freshmeat.sourceforge.net/projects/lrzsz/ 2)tar zxvf lrzsz-0.12.20.tar.gz 3)mv lrzsz-0.12 ...

  3. JTopo 使用

    1. 下载JTopo js http://www.jtopo.com/download.html 2. 引入js文件,引入jtopo之前引入jQuery 3. JTopo Demo -- 圆形布局 步 ...

  4. Factorial Trailing Zeroes (Divide-and-Conquer)

    QUESTION Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should ...

  5. 一些unity问题的收集

    ---恢复内容开始--- 1.Mono打不开且鼠标点击标签页无反应的解决办法 http://answers.unity3d.com/questions/574157/monodevelop-not-o ...

  6. ECMAScript5之JSON对象属性的遍历顺序

    测试浏览器 Chrome.Safari 一 键可以用parseInt解析成整数的,按数值升序顺序. var intObj = { '3.3' : 3.3, '2' : 222, '1' :111 } ...

  7. 使用Maven部署构件至私服

    --------------------siwuxie095                                 使用 Maven 部署构件至私服         1.部署构件到 Nexu ...

  8. 动态输出的javascript中alert文本的换行问题

    这个简单<%out.println("<script>alert('姓名:xx\\n性别:女\\n爱好:吃\\n')</script>");%> ...

  9. 分享chrome清空缓存开发小技巧

    在打开开发者工具的前提下,左键长按刷新页面小图标(左上角,地址栏左侧),可以调出清空缓存下拉选择项.

  10. $.post 提示错误: Uncaught SyntaxError: Unexpected token :

    $.post("addRecommond",{"productId":productId,"categoryCode":categoryCo ...