winform datagridview 添加行号。

先上图。

 

 代码如下:

 

 

View Code
 1  private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
 2         {
 3             var dgv = (DataGridView)sender;
 4             if (dgv.RowHeadersVisible)
 5             {
 6                 Rectangle rect = new Rectangle(e.RowBounds.Left, e.RowBounds.Top,
 7                                                dgv.RowHeadersWidth, e.RowBounds.Height);
 8                 rect.Inflate(-2-2);
 9                 TextRenderer.DrawText(e.Graphics,
10                     (e.RowIndex + 1).ToString(),
11                     e.InheritedRowStyle.Font,
12                     rect, e.InheritedRowStyle.ForeColor,
13                     TextFormatFlags.Right | TextFormatFlags.VerticalCenter
14                     );
15 
16             }
17         }
http://www.cnblogs.com/85538649/archive/2011/09/15/2177275.html#

 

posted on   jackdesk  阅读(247)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示