`
xuxujiang0
  • 浏览: 18107 次
  • 性别: Icon_minigender_1
  • 来自: 中山
社区版块
存档分类
最新评论

让DataGridView显示行号

    博客分类:
  • c#
阅读更多

     为了表示行号,我们可以在DataGridView的RowPostPaint事件中进行绘制。
RowPostPaint事件,具体可以参照MSDN。

   private   void  dataGridView1_RowPostPaint( object  sender, DataGridViewRowPostPaintEventArgs e)
        {
            Rectangle rectangle 
=   new  Rectangle(e.RowBounds.Location.X,
                e.RowBounds.Location.Y,
                dataGridView1.RowHeadersWidth 
-   4 ,
                e.RowBounds.Height);

            TextRenderer.DrawText(e.Graphics, (e.RowIndex 
+   1 ).ToString(), 
                dataGridView1.RowHeadersDefaultCellStyle.Font,
                rectangle,
                dataGridView1.RowHeadersDefaultCellStyle.ForeColor, 
                TextFormatFlags.VerticalCenter 
|  TextFormatFlags.Right);
        }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics