使用dataGridView控件常遇到的问题就是如何绘制行号,记录在下以方便日后查看
//绘制表格行号
private void dataGridView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
DataGridView dataGridView = (DataGridView)sender;
SolidBrush b = new SolidBrush(dataGridView.RowHeadersDefaultCellStyle.ForeColor);
e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), dataGridView.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 6);
}