cxgrid添加行号

简介:

TMyCxGrid = class(TObject)
    class procedure DrawIndicatorCell( Sender: TcxGridTableView; ACanvas: TcxCanvas;
      AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
  end;


class procedure TMyCxGrid.DrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
var
  FValue: string;
  FBounds: TRect;
  //method 2
  AIndicatorViewInfo: TcxGridIndicatorRowItemViewInfo;
  ATextRect: TRect;
  AFont: TFont;
  AFontTextColor, AColor: TColor;
begin
  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,
      False, False, 'NO',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 AIndicatorViewInfo.GridRecord.Selected then
    AFont.Style := ACanvas.Font.Style + [fsBold]
  else
    AFont.Style := ACanvas.Font.Style - [fsBold];

  Sender.LookAndFeelPainter.DrawHeader(ACanvas, AViewInfo.ContentBounds,
    ATextRect, [], [bBottom, bLeft, bRight], cxbsNormal, taCenter, TcxAlignmentVert.vaCenter,
    False, False, IntToStr(AIndicatorViewInfo.GridRecord.Index + 1),
    AFont, AFontTextColor, AColor);
  ADone := True;

end;

-----------------

然后调用即可:

tvList.OptionsView.Indicator:=True;
tvList.OptionsView.IndicatorWidth:=30;
tvList.OnCustomDrawIndicatorCell:= TMyCxGrid.DrawIndicatorCell;















本文转自鹅倌51CTO博客,原文链接: http://blog.51cto.com/kaixinbuliao/1633307,如需转载请自行联系原作者

相关文章
C#编程-72:dataGridView删除行
C#编程-72:dataGridView删除行
309 0
|
6月前
dataGrid 删除行和添加行
dataGrid 删除行和添加行
61 0
cxgrid多选获取记录。不需要设置KeyFieldName
procedure CopyGridRecordToJsn(pvDataSet: TcxGridDBTableView; pvValueJsn:    ISuperObject);var  i, j: Integer;  lvField: TcxGridDBColumn;  lvItem: I...
793 0