改成这样没错,巷列为空的序号也为空了。Dim dr As DataRow
dr = e.DataTable.Find("[_SortKey] < " & e.DataRow("_SortKey"), "[_SortKey] Desc")
If dr Is Nothing Then '如果是第一行,计算结存
e.DataRow("序号") = 1
dr = e.DataRow
End If
Dim drs As List(of DataRow) = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey"), "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
If drs(i).IsNull("巷") Then
drs(i)("序号") = Nothing
Else
drs(i)("序号") = drs(i-1)("序号") + 1
End If
Next
[此贴子已经被作者于2020/12/23 11:28:07编辑过]