delphi 如何让tcxGrid左边显示序号

来源:互联网 发布:淘宝联盟怎么分享图文 编辑:程序博客网 时间:2024/05/16 15:57

第一步:

设置cxgrid的属性, OptionsView.Indicator = True

第二步:

写OnCustomDrawIndicatorCell方法

var
  FValue: string;
  FBounds: TRect;
begin
  if (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
  begin
    FValue :=IntToStr(TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Index+1);
    FBounds := AViewInfo.Bounds;
    ACanvas.FillRect(FBounds);
    ACanvas.DrawComplexFrame(FBounds, clBtnHighlight, clBtnShadow, [bBottom, bLeft, bRight], 1);
    InflateRect(FBounds, -1, -1);
    ACanvas.Font.Color := clBlack;
    ACanvas.Brush.Style := bsClear;
    ACanvas.DrawText(FValue, FBounds, cxAlignCenter or cxAlignTop);
    ADone := True;
  end;
end;

原创粉丝点击