其實這個方法就是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;
本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/estudy2008/archive/2007/08/09/1733546.aspx