以下為在網上查找到的代碼,可以顯示行號,但當記錄數量比較多,如幾萬條記錄時,則需要時間較長,如何優化這個問題?
private   void   dataGrid1_Paint(object   sender,   System.Windows.Forms.PaintEventArgs   e)   
{       
int   row   =1;       
int   y   =   0;   
if(this.currentDataSet   !=   null)   
{   
int   count   =this.currentDataSet.Tables[0].Rows.Count;         
while(   row   <=   count)       
{     
//get   &   draw   the   header   text...           
string   text   =   string.Format("   {0}",   row);
y   =   this.dataGrid1.GetCellBounds(row   -   1,   0).Y   +   2;      
e.Graphics.DrawString(text,this.dataGrid1.Font,   new   SolidBrush(Color.Black),2,y);    
row   ++;       
}   
}     
}