其实这个方法就是cxGrid范例中提供的,原范例在CellLevelMultiselectDemo目录下

把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 on 2011-03-27 23:31  fyen  阅读(519)  评论(0编辑  收藏  举报