I checked several examples online. If there is no problem with the amount of data, once the amount of data is large, it is very slow, and there is a shortcoming to drag the high time when dragging the line is changed, and there are several The serial number is displayed in a cell. I have summarized their algorithms and write a DataGrid that is more good. Principle: Only the serial number of the line displayed in the table is displayed and dragged the line, and the line number moves together.
Override protected void onpaint (Painteventargs E)
{
Base.onpaint (e);
Try
{
IF (this.DataSource! = NULL)
{
Int Ydelta;
System.drawing .Rectangle Cell = this.getcellbounds (0, 0);
INT Y = Cell.top 2;
E.Graphics.drawstring ("Number", This.Font, New Solidbrush (Color.Black), 8, Y-18); //
IF (this.visibleRowCount> 0) // Only display the serial number in the table when there is a recordset
{
Currencymanager cm;
Cm = (currencessManager) this.bindingContext [this.datasource, this.datamember];
IF (cm.count> 0)
{
INT nrow = -1;
Y = 41; / / for the first line default height
While (NROW <0)
{
nrow = this.hittest (8, y) .ROW;
y ;
}
INT ncount = 0;
While (Y { String text = string.format ("{0}", NROW NCOUNT 1); E.Graphics.drawstring (Text, this.font, new solidbrush (color.black), 10, y) YDELTA = this.getcellbounds (nrow ncount, 0) .height 1; // **** Indicates a high degree of parameters Y = ydelta; / / If the following is distinguished from the son line display sequence number IF (this.isexpanded (NROW NCOUNT) && nrow ncount 1 Y = this.getcellbounds (NROW NCOUNT 1, 0). HEIGHT 3; } NCOUNT ; } } } } } Catch {} } Heavy loaded Paint in DataGrid, which is particularly convenient for the district, and hopes to share with you. My email: gangleader@126.com