

private void dgvData_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
Color color = dgvData.RowHeadersDefaultCellStyle.ForeColor;
if (dgvData.Rows[e.RowIndex].Selected)
color = dgvData.RowHeadersDefaultCellStyle.SelectionForeColor;
else
color = dgvData.RowHeadersDefaultCellStyle.ForeColor;
using (SolidBrush b = new SolidBrush(color))
{
e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 10, e.RowBounds.Location.Y + 6);
}
}