datagridview 添加行号

//显示datagridview 行号
private void kryptonDataGridView_sublstsfc_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(e.RowBounds.Location.X,
e.RowBounds.Location.Y,
kryptonDataGridView_sublstsfc.RowHeadersWidth - 4,
e.RowBounds.Height);

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

快乐而轻松的写代码
原文地址:https://www.cnblogs.com/libei/p/6518585.html