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. intellij idea14 +svn配置

    说明:使用TortoiseSVN客户端,安装时必须选择client tools,否则不会有svn.exe,也就不能支持intellij idea的svn插件,因为intellij idea是使用命令行 ...

  2. python2.7中可以使用到的一些模块地址

    1.reportlab:由很多部分组成且允许用户使用多种方法创建输出,地址: 下载ReportLab https://pypi.python.org/simple/reportlab/ http:// ...

  3. 二叉查找树迭代器 · Binary Search Tree Iterator

    [抄题]: 设计实现一个带有下列属性的二叉查找树的迭代器: 元素按照递增的顺序被访问(比如中序遍历) next()和hasNext()的询问操作要求均摊时间复杂度是O(1) 对于下列二叉查找树,使用迭 ...

  4. php中正则案例分析

    案例一如下: $regex='/[\s\S]*/'; $str='lemon'; $matches=array(); if(preg_match($regex,$str,$matches)){ var ...

  5. spring框架之AspectJ的XML方式完成AOP的开发

    1. 步骤一:创建JavaWEB项目,引入具体的开发的jar包 * 先引入Spring框架开发的基本开发包 * 再引入Spring框架的AOP的开发包 * spring的传统AOP的开发的包 * sp ...

  6. 轮播图jQuery

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. 779A Pupils Redistribution

    /* A. Pupils Redistribution time limit per test 1 second memory limit per test 256 megabytes input s ...

  8. 20172325 2017-2018-2 《Java程序设计》第六周学习总结

    20172325 2017-2018-2 <Java程序设计>第六周学习总结 教材学习内容总结 1.利用[ ]建立一个数组,整列数据可以通过数组名引用,数组中的每个元素则可以通过其在数组中 ...

  9. POJ3687.Labeling Balls 拓扑排序

    Labeling Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13201 Accepted: 3811 Descr ...

  10. 类方法 isAssignableFrom、instanceof 和 asSubclass

    类方法 isAssignableFrom.instanceof 和 asSubclass Spring 框架 CollectionFactory 的 asEnumType 方法使用 "类.a ...