网上最常见的做法是用DataGridView的RowPostPaint事件在RowHeaderCell中绘制行号:
privatevoiddataGridView1_RowPostPaint(objectsender, DataGridViewRowPostPaintEventArgs e)
         {
            try
             {
       e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, new SolidBrush(Color.CadetBlue), e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);
             }
            catch(Exception ex)
             {
                 MessageBox.Show("添加行号时发生错误,错误信息:"+ex.Message, "操作失败");
             }
         }
但是这种方法在大数据量的时候性能比较差,每次滚动数据都会触发RowPostPaint事件。
  posted on 2012-12-11 14:54 
Ke 阅读(2326) 
评论(1)  编辑  收藏  所属分类: 
C#