cxgrid显示行号

把cxGridView里OptionsView选项中的两项修改成如下

      OptionsView.Indicator = True
      OptionsView.IndicatorWidth = 40//宽度

在customDrawIndicatorCell事件中填写

procedure TForm1.cxGrid1BandedTableView1CustomDrawIndicatorCell(
  Sender: TcxGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
var
  AIndicatorViewInfo: TcxGridIndicatorRowItemViewInfo;
  ATextRect: TRect;
 // AStyle: TcxStyle;
  aCV:TcxCanvas;
begin
  if not (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
    Exit;
  aCV:=ACanvas ;
  ATextRect := AViewInfo.ContentBounds;
  AIndicatorViewInfo := AViewInfo as TcxGridIndicatorRowItemViewInfo;
  InflateRect(ATextRect, -2, -1);

  if AIndicatorViewInfo.GridRecord.Selected then  //这个if段是为了在行号处把把选中的行号跟别的区分开,可不用
  begin
    aCV.Font.Style := Canvas.Font.Style + [fsBold]; 
    aCV.Font.Color := clRed;
  end
  else
  begin
     aCV.Font.Style := Canvas.Font.Style - [fsBold];
     acv.Font.Color := Canvas.Font.Color;
  end;

  Sender.LookAndFeelPainter.DrawHeader(ACanvas, AViewInfo.ContentBounds,
    ATextRect, [], cxBordersAll, cxbsNormal, taCenter, vaCenter,
    False, False, IntToStr(AIndicatorViewInfo.GridRecord.Index + 1),
//    AStyle.Font, AStyle.TextColor, AStyle.Color);
  acv.Font,acv.font.Color,acv.Brush.color );
  ADone := True;
end;

posted @ 2011-01-22 15:54  delphi中间件  阅读(774)  评论(0编辑  收藏  举报