• 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;

    测试GridMode显示有问题。

  • 相关阅读:
    html 时间区间选择功能
    Django 【settings】数据库设置
    Django forms 定制form字段
    避免js全局变量污染的方法
    js获取路由
    采用遍历的方法获取字符串a在字符串b中的位置
    vue 学习笔记
    Promise
    js常用JSON数据操作
    js 数组遍历方式
  • 原文地址:https://www.cnblogs.com/china1/p/3400001.html
Copyright © 2020-2023  润新知