1. procedure SetRowNumber(var ASender: TcxGridTableView; AViewInfo: TcxCustomGridIndicatorItemViewInfo;
  2. var ACanvas: TcxCanvas; var ADone: boolean);
  3.  
  4. uses cxLookAndFeelPainters;
  5.  
  6. procedure SetRowNumber(var ASender: TcxGridTableView; AViewInfo: TcxCustomGridIndicatorItemViewInfo;
  7. var ACanvas: TcxCanvas; var ADone: boolean);
  8. var
  9. AIndicatorViewInfo: TcxGridIndicatorRowItemViewInfo;
  10. ATextRect: TRect;
  11. AFont: TFont;
  12. AFontTextColor, AColor: TColor;
  13. begin
  14. AFont := ACanvas.Font;
  15. AColor := clBtnFace;
  16. AFontTextColor := clWindowText ;
  17. if (AViewInfo is TcxGridIndicatorHeaderItemViewInfo) then begin
  18. ATextRect := AViewInfo.Bounds;
  19. InflateRect(ATextRect, -, -);
  20.  
  21. ASender.LookAndFeelPainter.DrawHeader(ACanvas, AViewInfo.Bounds,
  22. ATextRect, [], cxBordersAll, cxbsNormal, taCenter, vaCenter,
  23. False, False, '序号', AFont, AFontTextColor, AColor);
  24. ADone := True;
  25. end ;
  26. if not (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
  27. Exit;
  28. ATextRect := AViewInfo.ContentBounds;
  29. AIndicatorViewInfo := AViewInfo as TcxGridIndicatorRowItemViewInfo;
  30. InflateRect(ATextRect, -, -);
  31. ASender.LookAndFeelPainter.DrawHeader(ACanvas, AViewInfo.ContentBounds,
  32. ATextRect, [], [bBottom, bLeft, bRight], cxbsNormal, taCenter, vaCenter,
  33. False, False, IntToStr(AIndicatorViewInfo.GridRecord.Index + ),
  34. AFont, AFontTextColor, AColor);
  35. ADone := True;
  36. ASender.LookAndFeelPainter.DrawIndicatorImage(ACanvas, ATextRect, AIndicatorViewInfo.IndicatorKind);
  37. end;

如果你不要行标志的话,你可以不改控件 
直接注释掉这一行: ASender.LookAndFeelPainter.DrawIndicatorImage(ACanvas, ATextRect, AIndicatorViewInfo.IndicatorKind); 
要标志的话,在DrawIndicatorImage 从这里跟进去(Ctrl+左键单击) 
在 cxLookAndFeelPainters 单元中作如下修改:

  1. class procedure TcxCustomLookAndFeelPainter.DrawIndicatorImage(ACanvas: TcxCanvas;
  2. const R: TRect; AKind: TcxIndicatorKind);
  3. var
  4. X, Y: Integer;
  5. begin
  6. if AKind = ikNone then Exit;
  7. with cxIndicatorImages, R do
  8. begin
  9. X := (Left + Right - Width); //靠右
  10. Y := (Top + Bottom - Height) div ; //居中
  11. end;
  12. cxIndicatorImages.Draw(ACanvas.Canvas, X, Y, Ord(AKind) - );
  13. end;

注意,我已注明靠右的那一行, 就是去掉 DIV 2 了, 
还要改一个地方: 
SKIN控件目录下的dxSkinLookAndFeelPainter单元,找到 
TdxSkinLookAndFeelPainter.DrawIndicatorImage 函数 
的 
OffsetRect(ARect, (Left + Right - cx div 2) , (Top + Bottom - cy) div 2); 
这一行,将 (Left + Right - cx div 2) 改为(Left + Right - cx) 也是去掉 div 2 就是靠右; 
修改后: OffsetRect(ARect, (Left + Right - cx) , (Top + Bottom - cy) div 2);

使用

  1. procedure TForm1.cxGrid1DBTableView1CustomDrawIndicatorCell(
  2. Sender: TcxGridTableView; ACanvas: TcxCanvas;
  3. AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
  4. begin
  5. SetRowNumber(Sender,AviewInfo,ACanvas,ADone);
  6. end;

另外序号列的列宽最好改为35!

效果图:

Delphi cxGrid加行号的更多相关文章

  1. vim 加行号 和取消行号

    :set nu #是加行号 :set nonu #是去掉行号

  2. delphi cxgrid 使用方法

    delphi cxgrid 使用方法1.绑定数据 方法 cxGrid1DBTableView1.DataController.DataSource:=DataSource12.去掉"Drag ...

  3. jquery plugins —— datatables 增加行号

    table = $("#Table").DataTable({ "rowCallback": function (row, data, dataIndex) { ...

  4. vi命令加行号查找替换等命令

    一.加行号           : set nu二.vi查找:    当你用vi打开一个文件后,因为文件太长,如何才能找到你所要查找的关键字呢?在vi里可没有菜单-〉查找,              ...

  5. 关于Delphi cxGrid主从表中从表只能编辑第一条记录的问题

    在Delphi cxGrid主从表中从表只能编辑第一条记录,这个问题是由于设置主从关联字段错误造成的. 从表DBtableView2的keyfieldnames,DetailKeyFieldNames ...

  6. 怎么在SQL查询的结果里加行号?

    怎么在SQL查询的结果里加行号? 学习了:https://zhidao.baidu.com/question/91188037.html mysql : ) as rowNo From a, () ) ...

  7. 用UNIX的cat命令用于给文本加行号 (转载)

    转载:http://blog.csdn.net/vicant/article/details/2317721 有时候需要给文本加上行号,用UNIX的cat命令可以进行这项工作. cat命令的用法如下: ...

  8. C# datagridview、datagrid、GridControl增加行号

    01 - WinForm中datagridview增加行号 在界面上拖一个控件dataGridView1,在datagridview添加行事件中添加如下代码: private void dataGri ...

  9. Delphi CxGrid 汇总(4)

    1.     CxGrid汇总功能 ① OptionsView-Footer设置为True,显示页脚   ② CxGrid的Summary选项卡定义要汇总的列和字段名及汇总方式,Footer选项卡定义 ...

随机推荐

  1. python3——print使用

        print的初步认识:对于科班出身的或有相关经验的人来说,学习python是相当有趣的事,因为可以做日常任务, 比如自动备份你的MP3:可以做网站,如YouTube就是Python写的:可以做 ...

  2. jqgrid 滚动分页

    有时,我们不想在底部显示分页信息,而是通过用户滚动鼠标,当鼠标滚到到底自动加载下一页数据,再滚动再加载直至数据全部加载完毕.如何配置? 设置 scroll:true   emptyrecords用于在 ...

  3. DB2编目配置及管理

    打开命令:db2cmd 我一般打开的方式如下:                       (在db2)                                                 ...

  4. timestamp 字段

    项目中由于需求设计,数据库中需要一个timestamp时间戳类型的字段来作为区别数据添加和修改的标识.由于timestamp在SQL SERVER 2005数据库中,不可为空的timestamp类型在 ...

  5. R语言入门 :基本数据结构

    1.向量 向量是R语言中最基本的数据类型,在R语言中没有单独的变量. (1)  创建向量 R语言中可以用 = 或者 <- 来赋值. 向量名 <- 向量 或  向量名 = 向量 向量的创建方 ...

  6. 《基于Cortex-M4的ucOS-III的应用》课程设计 结题报告

    <基于Cortex-M4的ucOS-III的应用>课程设计 结题报告 小组成员姓名:20155211 解雪莹 20155217 杨笛 20155227 辜彦霖 指导教师:娄嘉鹏 一.设计方 ...

  7. 20155237 《JAVA程序设计》实验二(JAVA面向对象程序设计)实验报告

    20155237 <JAVA程序设计>实验二(JAVA面向对象程序设计)实验报告 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S ...

  8. [清华集训2015 Day2]矩阵变换-[稳定婚姻模型]

    Description 给出一个N行M列的矩阵,保证满足以下性质: M>N. 矩阵中每个数都是 [0,N]中的自然数. 每行中, [1,N]中每个自然数刚好出现一次,其余的都是0. 每列中,[1 ...

  9. Keras实现风格迁移

    风格迁移 风格迁移算法经历多次定义和更新,现在应用在许多智能手机APP上. 风格迁移在保留目标图片内容的基础上,将图片风格引用在目标图片上. 风格本质上是指在各种空间尺度上图像中的纹理,颜色和视觉图案 ...

  10. 【第三课】Centos 7.x系统安装和网络配置以及远程密钥登录

    目录 一.安装CentOS 7.3 二.配置网络 1.使用dhclient命令自动获取ip地址 2.使用ip addr或ifconfig命令查看网卡信息 3.使用route命令查看路由信息 4.通过修 ...