这是效果图:
在dataGridView 的RowPostPaint 事件是加入如下代码:
// 这是加入行号的代码
using (SolidBrush b = new SolidBrush(dataGridView1.RowHeadersDefaultCellStyle.ForeColor))
{
e.Graphics.DrawString((Convert.ToInt32(e.RowIndex) + 1).ToString(System.Globalization.CultureInfo.CurrentCulture), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
}
//这是了隔行换色的代码
this.dataGridView1.RowsDefaultCellStyle.BackColor = Color.FromArgb(4, 230, 228);
this.dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(187, 227, 227);
this.dataGridView1.GridColor = Color.FromArgb(208, 255, 255);