Listbox 多选的问题

来源:百度知道 编辑:UC知道 时间:2024/05/21 09:58:21
设计是这样的,两个Listbox,中间是两个按钮,点击按钮1,将左边Listbox选中的项删除、加入到右面Listbox中,Listbox的Mutiselect=1,也就是支持选中多个,
请问按钮1的代码如何编写,主要是选中多项怎么做。谢谢

Private Sub Command1_Click()
Dim i%

Do Until i = List1.ListCount
If List1.Selected(i) = True Then
List2.AddItem List1.List(i)
List1.RemoveItem i
Else
i = i + 1
End If
Loop
End Sub

Private Sub Form_Load()
List1.Clear
List2.Clear
Command1.Caption = "移动"
For i = 1 To 20
List1.AddItem "这是测试第" & i & "条!"
Next
End Sub