第1个回答 2012-08-28
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
DataGridView temp = (DataGridView)sender;
using (SolidBrush b = new SolidBrush(temp.RowHeadersDefaultCellStyle.ForeColor))
{
if(e.RowIndex<10)
e.Graphics.DrawString(Convert.ToString("00"+e.RowIndex + 1, System.Globalization.CultureInfo.CurrentUICulture), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);
if (e.RowIndex < 100&&e.RowIndex>10)
e.Graphics.DrawString(Convert.ToString("0" + e.RowIndex + 1, System.Globalization.CultureInfo.CurrentUICulture), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);
if (e.RowIndex < 1000 && e.RowIndex > 100)
e.Graphics.DrawString(Convert.ToString(e.RowIndex + 1, System.Globalization.CultureInfo.CurrentUICulture), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);
}
}
private void dataGridView1_Paint(object sender, PaintEventArgs e)
{
DataGridView temp = (DataGridView)sender;
using (SolidBrush b = new SolidBrush(temp.RowHeadersDefaultCellStyle.ForeColor))
{
e.Graphics.DrawString("序号", temp.Font, b, 8, 5);
}
}
你看着改动下吧,基本就是这样的本回答被提问者采纳