Removing items from an extended multi-select ListBox
Hi there ...
I'm posing this question cause I'll be hanged if I remember how I did this before ... :D I have an extended multi-select listbox where it is loaded by the user from a combobox and a textbox ... When the user selects at least 1 row in the listbox to remove, I need to traverse the list of selected items and add them back into the combobox (Done!) and them delete the rows from the list box ... And note that iterating thru the ItemsSelected collection and removing the 1st item works but subsequent iterations fail because the Selected flag for the other items have been reset... I vaguely recall copying the itemsselected collection ... Anyone remembering this little trick, I would appreciate a refresher on it... Thanks!
- Mike
[771 byte] By [
M Owen] at [2007-11-18 2:14:39]

# 1 Re: Removing items from an extended multi-select ListBox
Simple all you have to do is this.
Transfer in the combobox all the items selected first and once this is done you can take out all the items that were selected from the list.
The easiest way is to put the strings of all the item selected in an array and take them out one at a time.
# 2 Re: Removing items from an extended multi-select ListBox
Or you can take them out from the last to the first, using that will prevent others items to change index.
JeffB
JeffB at 2007-11-10 0:03:37 >

# 3 Re: Removing items from an extended multi-select ListBox
Guys ...
Ok. I have effected the transfer ... Jeff, I tried iterating from last to 1st ... When I use the listbox's collection or even traverse on the Selected property the 1st removal (RemoveItem method call) blows me out of the water from removing the rest of the "selected" items and that's in quotes because they aren't selected no more ... What I need to do (and the thrust of my recollection) is copy/make an array of the selected items outside of the listbox and do the dirty deed from it... I kinda answered my own question ... I thought there was a method for getting the selected items and putting it into a user-defined array ...
- Mike
M Owen at 2007-11-10 0:04:35 >

# 4 Re: Removing items from an extended multi-select ListBox
Ok ... Well here's what I came up with ... Enjoy! (Or rip to pieces ...)
Private Sub RemoveButton_Click()
If BreakDownList.ItemsSelected.Count < 1 Then Exit Sub
Dim i As Long, BDRow As Variant, SelArray() As Integer
i = 1
ReDim SelArray(BreakDownList.ItemsSelected.Count)
For Each BDRow In BreakDownList.ItemsSelected
AvailQty = AvailQty + CDbl(BreakDownList.Column(1, BDRow))
WO_ComboBox.AddItem BreakDownList.Column(0, BDRow)
SelArray(i) = BDRow
i = i + 1
Next BDRow
For i = BreakDownList.ItemsSelected.Count To 1 Step -1
BreakDownList.RemoveItem (SelArray(i))
Next
AvailQtyLbl.Caption = AvailQty
End Sub
M Owen at 2007-11-10 0:05:39 >
