这样写,如果出错,就请上传例子。
Select Case e.DataCol.Name
Case "项目名称","工程单位名称","费用类别","费用类别1","进度金额"
Dim dr As DataRow
Dim mr As DataRow = e.DataRow
Dim drs As List(of DataRow)
dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [项目名称] = '" & mr("项目名称") & "' And [工程单位名称] = '" & mr("工程单位名称") & "' And [费用类别] = '" & mr("费用类别") & "' And [费用类别1] = '" & mr("费用类别1") & "'", "[_SortKey] Desc")
If dr Is Nothing Then
mr("累计进度") = mr("进度金额")
dr = mr
End If
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [项目名称] = '" & dr("项目名称") & "' And [工程单位名称] = '" & dr("工程单位名称") & "' And [费用类别] = '" & dr("费用类别") & "' And [费用类别1] = '" & dr("费用类别1") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("累计进度") = drs(i-1)("累计进度") + drs(i)("进度金额")
Next
If e.DataCol.Name = "项目名称" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [项目名称] = '" & e.OldValue & "' And [工程单位名称] = '" & dr("工程单位名称") & "' And [费用类别] = '" & dr("费用类别") & "' And [费用类别1] = '" & dr("费用类别1") & "'", "[_SortKey] Desc")
If dr Is Nothing Then
dr = e.DataTable.Find("[项目名称] = '" & e.OldValue & "' And [工程单位名称] = '" & dr("工程单位名称") & "' And [费用类别] = '" & dr("费用类别") & "' And [费用类别1] = '" & dr("费用类别1") & "'", "[_SortKey]")
If dr IsNot Nothing Then
dr("累计进度") = dr("进度金额")
End If
End If
If dr IsNot Nothing Then
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [项目名称] = '" & dr("项目名称") & "' And [工程单位名称] = '" & dr("工程单位名称") & "' And [费用类别] = '" & dr("费用类别") & "' And [费用类别1] = '" & dr("费用类别1") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("累计进度") = drs(i-1)("累计进度") + drs(i)("进度金额")
Next
End If
End If
If e.DataCol.Name = "费用类别1" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [项目名称] = '" & dr("项目名称") & "' And [工程单位名称] = '" & dr("工程单位名称") & "' And [费用类别] = '" & dr("费用类别") & "' And [费用类别1] = '" & e.Oldvalue & "'", "[_SortKey] Desc")
If dr Is Nothing Then
dr = e.DataTable.Find("[项目名称] = '" & dr("项目名称") & "' And [工程单位名称] = '" & dr("工程单位名称") & "' And [费用类别] = '" & dr("费用类别") & "' And [费用类别1] = '" & e.Oldvalue & "'", "[_SortKey]")
If dr IsNot Nothing Then
dr("累计进度") = dr("进度金额")
End If
End If
If dr IsNot Nothing Then
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [项目名称] = '" & dr("项目名称") & "' And [工程单位名称] = '" & dr("工程单位名称") & "' And [费用类别] = '" & dr("费用类别") & "' And [费用类别1] = '" & dr("费用类别1") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("累计进度") = drs(i-1)("累计进度") + drs(i)("进度金额")
Next
End If
End If
If e.DataCol.Name = "费用类别" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [项目名称] = '" & dr("项目名称") & "' And [工程单位名称] = '" & dr("工程单位名称") & "' And [费用类别] = '" & e.OldValue & "' And [费用类别1] = '" & dr("费用类别1") & "'", "[_SortKey] Desc")
If dr Is Nothing Then
dr = e.DataTable.Find("[项目名称] = '" & dr("项目名称") & "' And [工程单位名称] = '" & dr("工程单位名称") & "' And [费用类别] = '" & e.OldValue & "' And [费用类别1] = '" & dr("费用类别1") & "'", "[_SortKey]")
If dr IsNot Nothing Then
dr("累计进度") = dr("进度金额")
End If
End If
If dr IsNot Nothing Then
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [项目名称] = '" & dr("项目名称") & "' And [工程单位名称] = '" & dr("工程单位名称") & "' And [费用类别] = '" & dr("费用类别") & "' And [费用类别1] = '" & dr("费用类别1") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("累计进度") = drs(i-1)("累计进度") + drs(i)("进度金额")
Next
End If
End If
If e.DataCol.Name = "工程单位名称" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [项目名称] = '" & dr("项目名称") & "' And [工程单位名称] = '" & e.OldValue & "' And [费用类别] = '" & dr("费用类别") & "' And [费用类别1] = '" & dr("费用类别1") & "'", "[_SortKey] Desc")
If dr Is Nothing Then
dr = e.DataTable.Find("[项目名称] = '" & dr("项目名称") & "' And [工程单位名称] = '" & e.OldValue & "' And [费用类别] = '" & dr("费用类别") & "' And [费用类别1] = '" & dr("费用类别1") & "'", "[_SortKey]")
If dr IsNot Nothing Then
dr("累计进度") = dr("进度金额")
End If
End If
If dr IsNot Nothing Then
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [项目名称] = '" & dr("项目名称") & "' And [工程单位名称] = '" & dr("工程单位名称") & "' And [费用类别] = '" & dr("费用类别") & "' And [费用类别1] = '" & dr("费用类别1") & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("累计进度") = drs(i-1)("累计进度") + drs(i)("进度金额")
Next
End If
End If
End Select