首先要保证显示RowHeader列,然后在DataGridView的RowPostPaint事件中写如下代码:
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
using (SolidBrush b = new SolidBrush(dataGridView1.RowHeadersDefaultCellStyle.ForeColor))
{
e.Graphics.DrawString(e.RowIndex.ToString(System.Globalization.CultureInfo.CurrentUICulture), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
}
}
追问RowPostPaint事件没找到啊!RowHeader列显示属性在哪儿设置?
追答dataGridView1.RowHeadersVisible = true;//显示行头
本回答被网友采纳