这里有一个问题:当List的项目被删除一项后For r = 0 To List2.ListCount - 1中的ListCount已经不是原来的ListCount,如果在循环肯定出错。试想一想,如果List中全部被选,按理只需循环ListCount就可以了,当删除到最后一个时ListCount将=0,也就是说List1.RemoveItem r中的r将=0。
如果采用Collection对象,将不需要删除的项目添加到Collection对象,然后再将Collection对象中的项目遍历罗列出添加到List1中。
试一试这个:
Option Explicit
Private C As Collection
Private Sub Command1_Click()
Dim i As Integer
Dim x As Variant
Set C = New Collection
For i = 1 To List1.ListCount
If List1.Selected(i - 1) = False Then C.Add List1.List(i - 1)
Next
List1.Clear
For Each x In C
List1.AddItem x
Next
Set C = Nothing
End Sub
Private Sub Form_Load()
Dim i As Integer
With List1
For i = 1 To 100
.AddItem i
Next
End With
End Sub
[此贴子已经被作者于2006-5-13 23:14:31编辑过]