为DataGridView添加行号
一,为DataGridView添加RowPostPaint事件
二,为该事件添加如下代码
private void dgvShow_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, this.dgvShow.RowHeadersWidth - 4, e.RowBounds.Height); TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), this.dgvShow.RowHeadersDefaultCellStyle.Font, rectangle, this.dgvShow.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}
浙公网安备 33010602011771号