cxGrid1 自动编号 问题(10)

Z

zqssoft

Unregistered / Unconfirmed
GUEST, unregistred user!
在DBGrid1这个控件中,行自动编号是这样的:procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);beginif Column.Index=0 then dbgrid1.Canvas.TextRect(Rect,Rect.Left+10,Rect.Top,InttoStr(dbgrid1.DataSource.DataSet.RecNo));end;但是我现在用cxGrid1这个控件,如何让他出现像上面DBGrid一样原理的自动编号列?
 
这个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;
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
873
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
顶部