Private Sub cmdUp_Click()
On Error Resume Next
Dim nItem As Integer
With listview1
If .ListIndex < 0 Then Exit Sub
nItem = .ListIndex
If nItem = 0 Then Exit Sub
'不能将第一个项目向上移动
'向上移动项目
.AddItem .Text, nItem - 1
'删除旧的项目
.RemoveItem nItem + 1
'选择刚刚被移动的项目
.Selected(nItem - 1) = True
End With
End Sub
Private Sub cmdDown_Click()
On Error Resume Next
Dim nItem As Integer
With listview1
If .ListIndex < 0 Then Exit Sub
nItem = .ListIndex
If nItem = .ListCount - 1 Then Exit Sub '不能将最后的项目向下移动
'向下移动项目
.AddItem .Text, nItem + 2
'删除旧的项目
.RemoveItem nItem
'选择刚刚被移动的项目
.Selected(nItem + 1) = True
End With
End Sub