我的DataGridView1有850行60列數據,我用
DataGridView.Rows[10].HeaderCell.Value="第十行";
就出錯 說超出索引範圍, 但是用DataGridView.Rows[10].Cell[2].Value是可以正常取出單元格的值的不會提示超出索引範圍
爲什麽DataGridView.Rows[10].HeaderCell.Value中的Rows[10]就會超出索引範圍
DataGridView.Rows[10].Cell[2].Value中的Rows[10]就不會超出索引範圍,高手指點下啊,這個問題折磨我一早上了 我都快被整崩潰了!!!!!!!

解决方案 »

  1.   

    http://wenku.baidu.com/view/8f5b852d7375a417866f8f68.html
    看看这个,好像不能直接赋值,要重绘神马的,我也不懂。
      

  2.   

     private void dgGrid_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
     {
         ShowGridRowNumber(this.dgGrid, e);
     }
     public static void ShowGridRowNumber( DataGridView dgGrid, DataGridViewRowPostPaintEventArgs e)
     { 
       using (SolidBrush b = new SolidBrush(dgGrid.RowHeadersDefaultCellStyle.ForeColor))
       {
          //在指定位置并且用指定的 System.Drawing.Brush 和 System.Drawing.Font 对象绘制指定的文本字符串
          e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture),dgGrid.DefaultCellStyle.Font, b,e.RowBounds.Location.X + 5,e.RowBounds.Location.Y + 4);     
                                                          
                }        }