cxGrid默认不显示行号,但是可以通过cxGrid1DBTableView1CustomDrawIndicatorCell事件来重绘行号

选中cxGrid1DBTableView1,在OnCustomDrawIndicatorCell事件中,输入以下代码:

1
2
3
4
5
6
procedure TForm1.cxGrid1DBTableView1CustomDrawIndicatorCell(
  Sender: TcxGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
begin
  SetRowNumber(Sender, AviewInfo, ACanvas, ADone);//调用SetRowNumber函数,函数声明及实现见后
end;

SetRowNumber函数声明(注意函数声明的摆放位置,此处不在Form内):

1
2
procedure SetRowNumber(var Sender: TcxGridTableView; var AViewInfo: TcxCustomGridIndicatorItemViewInfo;
  ACanvas: TcxCanvas; var ADone: boolean);

SetRowNumber函数实现代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
procedure SetRowNumber(var Sender: TcxGridTableView; var AViewInfo: TcxCustomGridIndicatorItemViewInfo;
  ACanvas: TcxCanvas; var ADone: boolean);
var
  AIndicatorViewInfo: TcxGridIndicatorRowItemViewInfo;
  ATextRect: TRect;
  AFont: TFont;
  AFontTextColor, AColor: TColor;
  procedure DrawIndicatorImage(ACanvas: TcxCanvas;
    const R: TRect; AKind: TcxIndicatorKind);
  var
    X, Y: Integer;
  begin
    if AKind = ikNone then Exit;
    X := (R.Left + R.Right - cxLookAndFeelPainters.cxIndicatorImages.Width);
    Y := (R.Top + R.Bottom - cxLookAndFeelPainters.cxIndicatorImages.Height) div 2;
    cxLookAndFeelPainters.cxIndicatorImages.Draw(ACanvas.Canvas, X, Y, Ord(AKind) - 1);
  end;
begin
  try
    AFont := ACanvas.Font;
    AColor := clBtnFace;
    AFontTextColor := clWindowText;
    if (AViewInfo is TcxGridIndicatorHeaderItemViewInfo) then begin
      ATextRect := AViewInfo.Bounds;
      InflateRect(ATextRect, -1, -1);
      Sender.LookAndFeelPainter.DrawHeader(ACanvas, AViewInfo.Bounds,
        ATextRect, [], cxBordersAll, cxbsNormal, taCenter, TcxAlignmentVert.vaCenter,
        FalseFalse'序号', AFont, AFontTextColor, AColor);
      ADone := True;
    end;
    if not (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
      Exit;
    ATextRect := AViewInfo.ContentBounds;
    AIndicatorViewInfo := AViewInfo as TcxGridIndicatorRowItemViewInfo;
    InflateRect(ATextRect, -1, -1);
    if Sender.DataController.RecordCount > 0 then begin
      if AIndicatorViewInfo.GridRecord.Selected then
        AFontTextColor := clRed
      else
        AFontTextColor := clWindowText;
    end;
    Sender.LookAndFeelPainter.DrawHeader(ACanvas, AViewInfo.ContentBounds,
      ATextRect, [], [bBottom, bLeft, bRight], cxbsNormal, taCenter, TcxAlignmentVert.vaCenter,
      FalseFalse, IntToStr(AIndicatorViewInfo.GridRecord.Index + 1),
      AFont, AFontTextColor, AColor);
    ADone := True;
  except
  end;
  DrawIndicatorImage(ACanvas, ATextRect, AIndicatorViewInfo.IndicatorKind);
end;

最后将cxGrid1DBTableView1中的OptionView中的Indicator设为True, IndicatorWidth设为适合值即可。

cxGrid 显示行号及行号列列名的更多相关文章

  1. GridView 显示行号 设置行号列的宽度

    /// <summary> /// GridView 显示行号 设置行号列的宽度 /// </summary> /// <param name="gv" ...

  2. APISpace 尾号限行API接口 免费好用

    尾号限行是一种为了缓解城市交通压力而催生的交通制度,措施实施以后对城市交通拥堵起到缓解作用.每个地区的尾号限行规定都有所不同,具体的以当地的为准.   尾号限行API,提供已知所有执行限行政策的共计6 ...

  3. PyQt学习随笔:QTableWidget的visualRow、visualColumn、logicalRow、logicalColumn(可见行、逻辑行、可见列、逻辑列)相关概念及方法探究

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 一.概念 关于逻辑行logicalRow.列logicalColumn和可见行visualRow.列 ...

  4. 帆软FineReport报表由于使用HTML显示后无法控制行高

    问题:帆软FineReport报表由于使用HTML显示后无法控制行高. 原因:首先每行的第一个单元格是以HTML显示的,然后,数据库查询的数据集中,sql语句中包含这个代码:'<pre>' ...

  5. excel VBA正则匹配单元格符号,并按符号把单元格拆分行(这里是按第一列分行,分行是从活动单元格的行开始,分行前需要选择所有需要填充内容的列,否则需要后期手动填充)

    Sub W()   ' MsgBox "行数:" & Selection.Rows.Count    Dim rows_count As Integer    Dim ro ...

  6. linux 如何显示一个文件的某几行(中间几行)

    linux 如何显示一个文件的某几行(中间几行) [一]从第3000行开始,显示1000行.即显示3000~3999行 cat filename | tail -n +3000 | head -n 1 ...

  7. Android设置TextView显示一行或多行

    在listView的item中或者是特殊的业务需求中,会要求TextView的内容不完全显示,只有通过一个指定的操作后才显示所有的,比如说一个按钮或者是其它的什么控件. 要想实现这个效果并不难,只要控 ...

  8. miniui 给表格行添加监听事件的几种方法以及点击某列列名数据不能排序的问题

    最近在使用miniui框架做开发,在做表格行的点击监听事件中发现了几个属性,都可以起到监听效果但是执行的结果却大有不同.好了废话不多说,直接上代码. <div id="pageGrid ...

  9. linux指定只显示(只打印)文件中的某几行(中间几行)

    [一]从第3000行开始,显示1000行.即显示3000~3999行 cat filename | tail -n +3000 | head -n 1000 [二]显示1000行到3000行 cat ...

  10. 007_linux显示一个文件的某几行(中间几行)

    <1>从第3000行开始,显示1000行.即显示3000~3999行 cat -n filename | tail -n +3000 | head -n 1000 cat -n anaco ...

随机推荐

  1. PHP-客户端的IP地址伪造、CDN、反向代理、获取的那些事儿

    外界流传的JAVA/PHP服务器端获取客户端IP都是这么取的: 伪代码: 1)ip = request.getHeader("X-FORWARDED-FOR")     可伪造,参 ...

  2. Python-正确使用Unicode

    正确处理文本,特别是正确处理Unicode.是个老生常谈的问题,有时甚至会难倒经验丰富的开发者.并不是因为这个问题很难,而是因为对软件中的文本,开发者没有正确理解一些关键概念及其表示方法.在Stack ...

  3. Linux的定时器

    在服务端程序设计中,与时间有关的常见任务有: 获取当前时间,计算时间间隔: 定时操作,比如在预定的时间执行一项任务,或者在一段延时之后执行一项任务. Linux 时间函数 Linux 的计时函数,用于 ...

  4. linux sudo命令详解

    --sudo命令重启网卡 sudo service network restart http://bestchenwu.iteye.com/blog/1450292

  5. bootstrap 警告

    本章将讲解警告(Alerts)以及Bootstrap所提供的用于警告的class.警告(Alerts)向用户提供了一种定义消息样式的方式.它们为典型的用户操作提供了上下文信息反馈. 您可以为警告框添加 ...

  6. Caused by: java.lang.NoSuchMethodException: <init> [class android.content.Context, interface android.util.AttributeSet] 异常

    1. 异常描述 FATAL EXCEPTION: main Process: com.whereru.greengrass.goforit, PID: 13847 java.lang.RuntimeE ...

  7. 企业信息系统集成框架(设计思路)C模式

    1.客户端.h文件 #pragma once #include<stdlib.h> //A程序员定义接口形式和调用模式 //初始化句柄 typedef int(*Init_Socket)( ...

  8. 【HTML+CSS】(2)CSS Sprite雪碧图

    1. 雪碧图的使用场景 (1). 静态图片.不随用户信息的变化而变化 (2). 小图片.图片容量比較小 (3). 载入量比較大 一些大图不建议拼成雪碧图,比如淘宝站点的导航图片都是使用的雪碧图. 2. ...

  9. Shell编程二

    告警系统需求分析 1.(虽然之前我们学习了zabbix,但有时候也不能满足我们的需求,比如比较冷门的监控项目需要写自定义脚本,或者服务器网络有问题,没有办法将客户端的数据发送到服务端.) 程序架构: ...

  10. openfireserver和jdk环境删除命令

    一.卸载jdk1.8 终端依次运行以下的命令 sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin sudo rm -rf / ...