private void dataGridView1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {            int row = 0;            int yDelta = dataGridView1.GetCellDisplayRectangle(row, 0, false).Height + 1;            int y = dataGridView1.GetCellDisplayRectangle(row, 0, false).Top + 2;            CurrencyManager cm = (CurrencyManager)this.BindingContext[dataGridView1.DataSource, dataGridView1.DataMember];            while (y < dataGridView1.Height - yDelta && row < cm.Count)
            {                //get   &   draw   the   header   text...                     string text = string.Format("{0}", row);                e.Graphics.DrawString(text, dataGridView1.Font, new SolidBrush(Color.Black), 12, y);                y += yDelta;                row++;
               
                
                            }                        }这段代码 是加行号标头的 通过该控件的Paint事件来不停的重绘

解决方案 »

  1.   

    DataColumn column;
    DataRow row;
    column = new DataColumn("任务ID");
    column.DataType = typeof(string);
      

  2.   

    显示行号的例子,
      private   void   dataGrid1_Paint(object   sender,   System.Windows.Forms.PaintEventArgs   e)  
      {  
       
       int   row   =0; 
       int   y   =   0;  
       int   i= this.table1.Count   ;//table1是数据源  
       while(   row   <   i)    
       {  
       string   text   =   string.Format("row{0}",   row);  
       y=this.dataGrid1.GetCellBounds(row,   0).Y   +2;  
       e.Graphics.DrawString(text,this.dataGrid1.Font,   new SolidBrush(Color.Black),   4,   y);   
       row++; 
       }    
      }