DataGridView 添加行号

Private Sub dgvData_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles dgvData.RowPostPaint
	Dim rectangle As Rectangle
 
	Try
		' Add Row Number
		rectangle = New Rectangle(e.RowBounds.Location.X, Convert.ToInt32(e.RowBounds.Location.Y + (e.RowBounds.Height - dgvData.RowHeadersDefaultCellStyle.Font.Size) / 2), dgvData.RowHeadersWidth - 4, e.RowBounds.Height)
 
		TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), dgvData.RowHeadersDefaultCellStyle.Font, rectangle, dgvData.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.Right)
 
	Catch ex As Exception
	    Throw ex
	End Try
End Sub
posted @ 2009-04-06 18:09  Wind·e  阅读(363)  评论(0编辑  收藏  举报