Winform 程序中DataGridView 控件添加行号

复制代码
  private void dataGridViewInventory_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
           var dgv = sender as DataGridView;
            if(dgv != null)
            {
                System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, dgv.RowHeadersWidth, e.RowBounds.Height);
                TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), dgv.RowHeadersDefaultCellStyle.Font, rectangle, dgv.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
            } }
复制代码

 

 

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