It is also to overload the ONPAINT method, but the method should be more clever! And don't worry about the title, don't use the coordinates, it is convenient! Protected override void onpaint (PainTeventargs e) {base.onpaint (e) ;
IF (this.DataSource! = null) {if (this.visibleRowcount == 0) return;
Rectangle currct;
Int irowcount = this.visibleRowcount; // There is an error in this side VisibleRowCount is limited to visible lines.
String stext = "";
INT nowy = 0;
For (int i = 0; i }} ================================================ =================== The place in the above is that this.visibleRowCount, only visible number of rows by visibleRowcount, so when the number of rows exceeds the visible range, The rest of the line is not drawn. The method of this number of lines has now been corrected. Which friend can be discussed together? Corrected implementation method is as follows: ======= ============================================================================================================================================================================================================= ========== Using system.data; use system.drawing; using system.windows.form; Namespace mycontrols {public class mydatagrid: DataGrid {Protected Override void onpaint (painteventargs e) {base.onpaint (e); Drawrownumber (E); } Private void DrawRownumber (Painteventargs E) {IF (this.DataSource! = Null && this.visibleRowCount! = 0) { Rectangle currct; INT IROWCOUNT = 0; Switch (this.DataSource.gettype (). TOSTRING ()) {case "system.data.dataset": // Binding object is DataSet IROWCOUNT = ((Dataset) this.DataSource) .tables [this.datamember] .rows .Count; break; case "system.data.dataable": // Bind object is DATATABLE IROWCOUNT = ((DATATABLE) this.DataSource) .Rows.count; break; case "system.data.dataview": // Tied The object is DataView Irowcount = (DataView) this.datasource .count; break; default: // Other object return;} For (int i = 0; i }}}