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
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, -, -); 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, -, -); 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 + ),
AFont, AFontTextColor, AColor);
ADone := True; end;

然后调用即可:

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

测试GridMode显示有问题。

上一篇:vue computed 可以使用getter和setter


下一篇:数据结构二叉树的递归与非递归遍历之java,javascript,php实现可编译(1)java