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

你可能感兴趣的:(datagridview)