我想將不超過8個選定項目從列表框1移動到列表框2。兩個列表框都是多選的。當我選擇多於8個項目並將它們一次移動到Listbox2時,這些項目不會從Listbox1中刪除。但是,如果我不嘗試限制可移動項目的數量,但我將其從ListBox1中移除時,將單獨移除它們(項目編號爲8的項目除外)。限制可以從一個列表框移動到另一個列表框的項目數量
如果我不嘗試限制可移動的項目數很難讓它與指定的條件一起工作(Listbox2中只有8個項目)。
我環顧四周,但找不到一個好例子。我真的很感謝建議。我也想知道我想要做的是不是可能的。
Private Sub BTN_MoveSelectedRight_Click()
Dim iCtr As Long
For iCtr = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(iCtr) = True And Not ListBox2.ListCount = 8 Then
Me.ListBox2.AddItem Me.ListBox1.List(iCtr)
End If
Next iCtr
For iCtr = Me.ListBox1.ListCount - 1 To 0 Step -1
If Me.ListBox1.Selected(iCtr) = True And Not ListBox2.ListCount = 8 Then
Me.ListBox1.RemoveItem iCtr
End If
Next iCtr
End Sub