Datagridview裏面的行自動編號

在相應的datagridview裏面添加RowPostPaint事件,代碼如下:

private void AAADGV_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            //自動編號與數據庫無關
            Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, AAADGV.RowHeadersWidth - 4,
             e.RowBounds.Height);
            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), AAADGV.RowHeadersDefaultCellStyle.Font, rectangle,
              AAADGV.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
        }

發佈了18 篇原創文章 · 獲贊 3 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章