/// <summary>
/// 添加行号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
Color color = dataGridView1.RowHeadersDefaultCellStyle.ForeColor;
if (dataGridView1.Rows[e.RowIndex].Selected)
color = dataGridView1.RowHeadersDefaultCellStyle.SelectionForeColor;
else
color = dataGridView1.RowHeadersDefaultCellStyle.ForeColor;
using (SolidBrush b = new SolidBrush(color))
{
e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 6);
}
}