呃,直接相加相除。
If e.DataCol.Name Like "硬度*" Then
Dim count As Integer = 0
Dim sum As Double = 0
For Each dc As DataCol In e.DataTable.datacols
If dc.name Like "硬度*" AndAlso e.DataRow.isnull(dc.name) = False Then
count += 1
sum += e.DataRow(dc.name)
End If
Next
If count > 0 Then
e.DataRow("平均硬度") = sum / count
Else
e.DataRow("平均硬度") = Nothing
End If
End If