Problem with use of ItemsSelected collection

N

noname

Is there a problem with using the ItemsSelected collection of a multi-select
listbox ?

I'm using the test code below (in the list click event) to return a
delimited string based on the items selected in a list. As the user selects
more items the string is modified. If the user selects (using the mouse) a
block of items (click-shift-click) all is fine and the correct list is
returned. If however the _last_ item in the selected group is de-selected
with the mouse (ctrl-click) then the function returns a list which correctly
includes the selected items but also, incorrectly, includes the item
immediately following the just de-selected item. Similar problems occur
de-selecting other previously selected items as 'ghost' seletions appear to
be made.

Private Sub lstTheList_Click()
Dim intTot As Integer
Dim intTotSel As Integer

Debug.Print "items>"; GetList(lstTheList, 1, ",", intTot, intTotSel)
End Sub

Public Function GetList(ctlList As ListBox, intColumn As Integer, strSep As
String, intTotalItems As Integer, intTotalSelected As Integer) As String

Dim varItem As Variant
Dim strSelection As String

strSelection = ""
intTotalSelected = 0

' build list of selected items
For Each varItem In ctlList.ItemsSelected
strSelection = strSelection & strSep & ctlList.Column(intColumn,
varItem)
intTotalSelected = intTotalSelected + 1
Next varItem

'<...more code to remove the first strSeparator>

GetList = strSelection

End Function

Any pointers to known problems with the property or my code gratefully
received.

TIA
Nigel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top