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. 如何禁止浏览器自动填充非登陆input的账号和密码?

    发现浏览器填充密码的方式,那就是,找到页面上第一个type为password的input填充.发现了这个规律后,很自然的就想到了,是不是可以在真正的password前面加一个隐藏的password,形 ...

  2. unity3d-ngui UIScrollView 滚动方向与滚轮相反

    生成一个滚动面板之后发现滚轮向上滚,界面向下:滚轮向下界面向上.在编辑窗口里发现这个选项 本来是-2,修改成正数就可以了. http://ju.outofmemory.cn/entry/146754

  3. 运行php网站需要安装什么

    php的运行环境: 为了能够运行php,有以下两种方法: 1. 使用支持php和MySQL的web主机(): 2. 本机(自己电脑)安装web服务器,然后安装MySQL和php. web虚拟主机: 大 ...

  4. .net调用web邮箱发送邮件(转载)

    public static void SendEmail() { System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient( ...

  5. OC - runtime - 1

  6. [leetcode]278. First Bad Version首个坏版本

    You are a product manager and currently leading a team to develop a new product. Unfortunately, the ...

  7. [leetcode]299. Bulls and Cows公牛和母牛

    You are playing the following Bulls and Cows game with your friend: You write down a number and ask ...

  8. SqlDataHelper

    using System;using System.Data;using System.Configuration;using System.Linq;using System.Web;using S ...

  9. Golang之Mysql事务

    Mysql事务 )原子性 )一致性 )隔离性 )持久性 示例代码 package main import ( "fmt" _ "github.com/go-sql-dri ...

  10. Linux 配置文件管理

    一.简介 参考:https://robots.thoughtbot.com/rcm-for-rc-files-in-dotfiles-repos http://dotfiles.github.io/ ...