如何设置 cxGrid1.Indicator 列标题(10)

Z

zqssoft

Unregistered / Unconfirmed
GUEST, unregistred user!
下面的代码完成后, Indicator的列标题是空的,怎么为Indicator列添加“序号”这个标题呢?//为cxgrid添加行号 cxGrid1DBTableView1.OptionsView.Indicator := True ; cxGrid1DBTableView1.OptionsView.IndicatorWidth := 40;//宽度procedure TForm1.cxGrid1DBTableView1CustomDrawIndicatorCell( Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);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;
 
这个cxGrid完全可以做到,你到Demo下看看,我这里发部分代码,其他还有个属性设置(好像是Indicator)忘记了,就是设置显示序号的。OnCustomDrawIndicatorCell事件:var AIndicatorViewInfo: TcxGridIndicatorRowItemViewInfo; ATextRect: TRect; AStyle: TcxStyle;begin if not (AViewInfo is TcxGridIndicatorRowItemViewInfo) then Exit; ATextRect := AViewInfo.ContentBounds; AIndicatorViewInfo := AViewInfo as TcxGridIndicatorRowItemViewInfo; InflateRect(ATextRect, -2, -1); if AIndicatorViewInfo.GridRecord.Selected then begin AStyle := styleSelected; end else begin AStyle := styleNormal; 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); ADone := True;end;
 
顶部