additem 添加属性
listcount总记录数
listindex索引值
Private Sub Form_Load()
List1.AddItem "广东省广州市"
List1.AddItem "广东省河源市"
List1.AddItem "广东省惠州市"
List1.ListIndex = 0
End Sub
Private Sub LeftAll_Click()
Dim i As Integer
For i = 0 To List2.ListCount - 1
List1.AddItem List2.List(i)
Next
List2.Clear
List1.ListIndex = List1.NewIndex
End Sub
Private Sub LeftOne_Click()
Dim i As Integer
If List2.ListCount = 0 Then Exit Sub
List1.AddItem List2.Text
i = List2.ListIndex
List2.RemoveItem i
List1.ListIndex = List1.NewIndex
If List2.ListCount > 0 Then
If i > List2.ListCount - 1 Then
List2.ListIndex = i - 1
Else
List2.ListIndex = i
End If
End If
End Sub
Private Sub List1_dblclick()
RightOne_Click
End Sub
Private Sub List2_dblClick()
LeftOne_Click
End Sub
Private Sub RightOne_Click()
Dim i As Integer
If List1.ListCount = 0 Then Exit Sub
List2.AddItem List1.Text
i = List1.ListIndex
List1.RemoveItem List1.ListIndex
If List1.ListCount > 0 Then
If i > List1.ListCount - 1 Then
List1.ListIndex = i - 1
Else
List1.ListIndex = i
End If
End If
List2.ListIndex = List2.NewIndex
End Sub
Private Sub RightALL_Click()
Dim i As Integer
For i = 0 To List1.ListCount - 1
List2.AddItem List1.List(i)
Next
List1.Clear
List2.ListIndex = 0
End Sub
Private Sub Up_Click()
Dim Up As Integer
With List2
If .ListIndex < 0 Then Exit Sub
Up = .ListIndex
If Up = 0 Then Exit Sub '不能将第一个项目向上移动
.AddItem .Text, Up - 1 '向上移动项目
.RemoveItem Up + 1 '删除旧的项目
.Selected(Up - 1) = True '选择刚刚被移动的项目
End With
End Sub
Private Sub Down_Click()
Dim Down As Integer
With List2
If .ListIndex < 0 Then Exit Sub
Down = .ListIndex
If Down = .ListCount - 1 Then Exit Sub '不能将最后的项目向下移动
.AddItem .Text, Down + 2 '向下移动项目
.RemoveItem Down '删除旧的项目
.Selected(Down + 1) = True '选择刚刚被移动的项目
End With
End Sub
附有截图
先新建两个listbox一个命名为:list1和一个list2
和六个命令按钮,详细命名见上图即可。为左、右、全左、全右、上、下