我是在编写上位机过程中,记录数据的时候需要添加显示功能,确认数据已记录,查看数据准确性。
DataGridView1.Columns.Add(0,"序号")'添加表头
Private Function ShowData() As Object
Dim n As Integer
Dim dr As DataGridViewRow = New DataGridViewRow
dr.CreateCells(DataGridView1)
n = DataGridView1.Rows.Count '行数
Try
For i As Integer = 0 To (10)
dr.Cells(i).Value = n
Next
Catch ex As Exception
return 0
End Try
DataGridView1.Rows.Add(dr)
End Function
把代码放到一个button下运行,效果如下。