c# winform DataGridView显示行号的方法,增加行号的代码

在DataGridView里加上这个事件 RowPostPaint

private void dataGridView1_[color=red]RowPostPaint[/color](object sender, DataGridViewRowPostPaintEventArgs e)
{
	Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
		e.RowBounds.Location.Y,
		dataGridView1.RowHeadersWidth - 4,
		e.RowBounds.Height);

	TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
	dataGridView1.RowHeadersDefaultCellStyle.Font,
		rectangle,
		dataGridView1.RowHeadersDefaultCellStyle.ForeColor,
		TextFormatFlags.VerticalCenter | TextFormatFlags.Right);

}


黑色头发:http://heisetoufa.iteye.com

你可能感兴趣的:(C++,c,C#,WinForm)