VB6.0中如何把Listbox的表项,上移或下移一个位置

来源:百度知道 编辑:UC知道 时间:2024/05/13 04:08:48
有两个button1,button2,
点button1向上移动一个,
点button2,向下移动一个
谁能实现,代码要简洁,我追加50分

'上移
Private Sub Command1_Click()
Dim n As Long
Dim s As String

If List1.ListIndex > 0 Then
n = List1.ListIndex
s = List1.List(n)
List1.RemoveItem List1.ListIndex
List1.AddItem s, n - 1
End If

End Sub

'下移
Private Sub Command2_Click()
Dim n As Long
Dim s As String

If List1.ListIndex <> -1 And List1.ListIndex < List1.ListCount - 1 Then
n = List1.ListIndex
s = List1.List(n)
List1.RemoveItem List1.ListIndex
List1.AddItem s, n + 1
End If

End Sub