datagridview 添加行号

时间:2021-12-08 07:33:05

//显示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);
}

datagridview 添加行号