Dim tb As Table=args(0)
Dim ss As String =args(1) ' 下移,上移
'上移
If ss ="上移" Then
'上移
If tb.Position>0 Then
Dim c As Integer = tb.current("II0")
Dim str As String=tb.DataTable.name
str=str.Remove(0,str.LastIndexOf("_")+1)
str=str & "id"
Dim cid As Integer =tb.current(str)
Dim r As Row = tb.rows(tb.current.index-1)
tb.current("II0")=r("II0")
r("II0")=c
tb.Sort="II0"
c=tb.FindRow("[" & str & "]=" & cid)
If c>=0 Then
tb.Position=c
End If
End If
Else
'下移
If tb.Position<tb.rows.count-1 Then
Dim c As Integer = tb.current("II0")
Dim str As String=tb.DataTable.name
str=str.Remove(0,str.LastIndexOf("_")+1)
str=str & "id"
Dim cid As Integer =tb.current(str)
Dim r As Row = tb.rows(tb.current.index+1)
tb.current("II0")=r("II0")
r("II0")=c
tb.Sort="II0"
c=tb.FindRow("[" & str & "]=" & cid)
If c>=0 Then
tb.Position=c
End If
End If
End If
这是最终代码。因为移动过程需要改变前行或后行的值,所以会导致当前行的改变,因为在移动后必须重新定位回到原来的当前行。