用静态变量标记一下:
Select e.DataCol.Name
Case "流程顺序"
Static bj As Boolean
If bj = True Then
Return
Else
bj = True
End If
Dim n As Integer = e.NewValue
Dim o As Integer = e.OldValue
Dim s As String = e.DataRow("_sortkey")
If n < o Then
Dim drs As List (Of DataRow) = e.DataTable.Select("办单号 = '" & e.DataRow("办单号") & "' and 流程顺序 >= " & e.NewValue & " and 流程顺序 < " & e.OldValue & " and _sortkey <> '" & s & "'" )
For Each dr As DataRow In drs
dr("流程顺序") = dr("流程顺序")+1
'msgbox("小于旧值")
Next
End If
If n > o Then
Dim drs As List (Of DataRow) = e.DataTable.Select("办单号 = '" & e.DataRow("办单号") & "' and 流程顺序 <= " & e.NewValue & " and 流程顺序 > " & e.OldValue & " and _sortkey <> '" & s & "'")
For Each dr As DataRow In drs
dr("流程顺序") = dr("流程顺序")-1
'msgbox("大于旧值")
Next
End If
Tables("工序工艺流程表").Sort = "流程顺序"
DataTables("工序工艺流程表").Save
bj = False
End Select