Delphi cxGrid加行号

 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, -1, -1);
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, -1, -1);
31   ASender.LookAndFeelPainter.DrawHeader(ACanvas, AViewInfo.ContentBounds,
32     ATextRect, [], [bBottom, bLeft, bRight], cxbsNormal, taCenter, vaCenter,
33     False, False, IntToStr(AIndicatorViewInfo.GridRecord.Index + 1),
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 单元中作如下修改:

class procedure TcxCustomLookAndFeelPainter.DrawIndicatorImage(ACanvas: TcxCanvas;
  const R: TRect; AKind: TcxIndicatorKind);
var
  X, Y: Integer;
begin
  if AKind = ikNone then Exit;
  with cxIndicatorImages, R do
  begin
    X := (Left + Right - Width);              //靠右
    Y := (Top + Bottom - Height) div 2;       //居中
  end;
  cxIndicatorImages.Draw(ACanvas.Canvas, X, Y, Ord(AKind) - 1);
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加行号,布布扣,bubuko.com

时间: 2024-08-03 14:04:26

Delphi cxGrid加行号的相关文章

delphi CXGRID用法 (取行、列值;定位选中某行等等)

CXGRID用法 (取行.列值:定位选中某行等等) Delphi Cxgrid获取选中行列,排序规则,当前正在编辑的单元格内的值 cxGrid1DBTableView1.Controller.FocusedRowIndex 当前行号 cxGrid1DBTableView1.Controller.FocusedRow 当前行 cxGrid1DBTableView1.Controller.FocusedColumn 当前列 cxGrid1DBTableView1.Controller.Focused

delphi cxgrid 使用方法

delphi cxgrid 使用方法1.绑定数据 方法 cxGrid1DBTableView1.DataController.DataSource:=DataSource12.去掉"Drag   a   column   header   here   to   group   by   that   column"方法cxGrid1DBTableView1.OptionsView.GroupByBox置为False3.去掉表头下三角数据 方法cxGrid1DBTableView1.O

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

转载:http://blog.csdn.net/vicant/article/details/2317721 有时候需要给文本加上行号,用UNIX的cat命令可以进行这项工作. cat命令的用法如下: NAME          cat - concatenate, copy, and print files SYNOPSIS          cat [-benrstuv] file ...Options      cat recognizes the following options:  

jquery plugins —— datatables 增加行号

table = $("#Table").DataTable({ "rowCallback": function (row, data, dataIndex) { //增加行号 $('td:eq(0)', row).html(dataIndex + table.page.info().length * table.page() + 1); }}); <table id="Table"> <thead> <tr styl

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

一.加行号           : set nu 二.vi查找:    当你用vi打开一个文件后,因为文件太长,如何才能找到你所要查找的关键字呢?在vi里可没有菜单-〉查找, 不过没关系,你在命令模式下敲斜杆(/)这时在状态栏(也就是屏幕左下脚)就出现了 "/"然后输入你要查找的关键字 敲回车就可以了.如果你要继续查找此关键字,敲字符n就可以继续查找了.值得注意的是"/"是向下查找,而"?" 是向上查找,而在键盘定义上"?"刚

delphi CxGrid用法总结(63问)

1. 去掉cxGrid中台头的Box 解决:在tableview1的optionsview的groupbybox=false; ***************************************************************************** 2.统计功能 解决:(1) tableview tableview1的optionsviewfooter=ture 然后在cxGRid1的customize..中的summary 的footer.add需要合计的列k

Delphi CxGrid 汇总(2)

17. 怎样设计多表头的cxGrid?解决:cxGrid可以解决如下的表头:---------------------------------| 说明1 | 说明2 |---------------------------------| 字段1 | 字段2 | 字段3 | 字段4 || 字段5 | 字段6 || 字段7 | 字段8 | 字段9 |实现这个很简单,你可以直接在上面拖动字段名,拖动时会显示箭头的,放入你想显示的位置就OK了.或者在鼠标右击cxGrid1DBBandedTableVie

Delphi CxGrid 汇总(4)

1.     CxGrid汇总功能 ① OptionsView-Footer设置为True,显示页脚   ② CxGrid的Summary选项卡定义要汇总的列和字段名及汇总方式,Footer选项卡定义单个汇总,Default For Groups定义按组汇总.OptionsView-GroupFooters设置为gfAlwaysVisible则显示按组汇总.设置后界面如图. 2.       CxGrid的样式设置 当设置了Kind时,NativeStyle必须设置为False,如果指定了Ski

Delphi : cxGrid的使用方法

1. 去掉cxgrid中抬头的box ,在tableview1的ptionsview的groupbybox=false; 2. 在GRID footer 中加入sum(列), tableview1的optionsview的footer=ture然后在cxGRid1的customize中的summary 的footer.add需要合计的列kind= skSum3. 去掉cxgrid 中的过滤下拉箭头选择tableview1.optionscustomize.columnfiltering=fasl