locked
Bug in ListBox property MultiSelect RRS feed

  • Question

  • There's an issue with the ListBox property MultiSelect when this property is set to 2 (Extended) (Office 2013). To reproduce, select a serried items in the ListBox. Then de-select an intermediate item. For example, you have selected 10 items, then de-select then

    seventh item. So nine items are selected, right? Now click on some control on the form or scroll through the ListBox. Access now shows only the first six items as selected.

    The value in de ListBox for each former selected item (nine items) is still correct: the property Count of the ItemsSelected collection returns the right 'selected' items, but - as said - only the first items are showed as selected. This seems to me a bug.
    The MultiSelect property is great, but very unfortunate that this problem with the value Exented occurs. In this way it can't be used.

    I've not yet tested in Office 2016.
    Is there someone with a solution?
    Sunday, November 15, 2015 2:44 PM

Answers

  • Hi Peter,

    Here's a couple more workarounds for you:

    1. Rather than using the scroll wheel on your mouse, try using the scroll bar to scroll through the list

    2. In the Lost Focus event of the Listbox, try the following code:

    Private Sub List0_LostFocus()
    Dim arr() As Boolean
    Dim x As Long
    
    ReDim arr(Me.List0.ListCount)
    
    For x = 0 To Me.List0.ListCount - 1
        arr(x) = Me.List0.Selected(x)
        Me.List0.Selected(x) = False
    Next
    
    For x = 0 To Me.List0.ListCount - 1
        Me.List0.Selected(x) = arr(x)
    Next
    
    End Sub
    
    Hope that helps...

    Sunday, November 15, 2015 5:20 PM
  • Hi DB Guy,

    Your workaround is almost perfect, but to place this in the MouseDown event is the solution bij scrolling with mouse and by scrolling bars.

    Sunday, November 15, 2015 6:48 PM

All replies

  • Hi Peter,

    I don't have 2013, but I can confirm the same behavior in 2010. I don't know either what's going on, but since you asked for a "workaround," here's what you could try:

    1. Select a series of items, from 1 to 10 for example

    2. De-select item #7

    3. Re-select item #7

    4. De-select item #7

    5. Scroll through the listbox or click on another control on the form

    A bit awkward but hope it helps...

    Sunday, November 15, 2015 4:42 PM
  • Hi Peter,

    Here's a couple more workarounds for you:

    1. Rather than using the scroll wheel on your mouse, try using the scroll bar to scroll through the list

    2. In the Lost Focus event of the Listbox, try the following code:

    Private Sub List0_LostFocus()
    Dim arr() As Boolean
    Dim x As Long
    
    ReDim arr(Me.List0.ListCount)
    
    For x = 0 To Me.List0.ListCount - 1
        arr(x) = Me.List0.Selected(x)
        Me.List0.Selected(x) = False
    Next
    
    For x = 0 To Me.List0.ListCount - 1
        Me.List0.Selected(x) = arr(x)
    Next
    
    End Sub
    
    Hope that helps...

    Sunday, November 15, 2015 5:20 PM
  • Hi DB Guy,

    This could be, indeed, a solution, but I think it will affect performance in case of long lists. In this case we've to create a procedure to call it in the event AfterUpdate of the ListBox. This procedure have to itterate over the selected items to determine which items are selected. Within that collection determine which item is the first non selected item. Select that item en de-select that item. Everytime when the ListBox is updated...

    Since this can lead to performance loss and problems with long lists, I dare not good at this. Rather than I prefer - but unfortunately - the MultiSelect value 1 (Simple). But thanks very much for your smart advice!

    Sunday, November 15, 2015 5:50 PM
  • Hi DB Guy,

    I was writing an answer, but I see you already have a second workaround. I'll examine it and wil respons.

    Sunday, November 15, 2015 5:57 PM
  • DB Guy,

    You are fantastic. Thanks so very much!

    Sunday, November 15, 2015 6:05 PM
  • This could be, indeed, a solution, but I think it will affect performance in case of long lists. In this case we've to create a procedure to call it in the event AfterUpdate of the ListBox. This procedure have to itterate over the selected items to determine which items are selected. Within that collection determine which item is the first non selected item. Select that item en de-select that item. Everytime when the ListBox is updated...

    Since this can lead to performance loss and problems with long lists, I dare not good at this. Rather than I prefer - but unfortunately - the MultiSelect value 1 (Simple). But thanks very much for your smart advice!

    Hi Peter,

    I still use A2003, so I am unfamiliar with the MultiSelect possibilities. But I developped a couple of routines that have analogues functionality.

    As I am always trying to learn more, I would like to know what the difference is between MultiSelect value 1 (Simple) and MultiSelect value 2 (Extended)?

    And for what kind of purposes you need to multiselect from a long list?

    Imb.

    Sunday, November 15, 2015 6:07 PM
  • Hi Imb-hb,

    The basics you have to know is to find the right information about objects, properties, methods, events. Here is a link for the answers of your question:

    https://msdn.microsoft.com/EN-US/library/office/ff195771.aspx

    Sunday, November 15, 2015 6:16 PM
  • Hi DB Guy,

    Unfortunately, the workaround does'nt work by scrolling... (scroll bar/mouse) But we are on our way to a solution.

    Sunday, November 15, 2015 6:21 PM
  • Hi DB Guy,

    Your workaround is almost perfect, but to place this in the MouseDown event is the solution bij scrolling with mouse and by scrolling bars.

    Sunday, November 15, 2015 6:48 PM
  • The basics you have to know is to find the right information about objects, properties, methods, events. Here is a link for the answers of your question:

    https://msdn.microsoft.com/EN-US/library/office/ff195771.aspx

    Hi Peter,

    Thanks for the link. I have studied it, and I think that I know how it works.

    I do not use ListBoxes at all. Instead I use normal form to display. This form can have a default selection and ordening, but it can be changed dynamically by the user to make his own selection on any field or combination of fields, and sorting, to choose from.

    Besides, within this form there is a Selection (boolean) field that can be ticked or de-ticked. Using the rightmouse one can tick or de-tick all Selection fields in between. The drawback on this moment is that it in fact a single-user feature is, while the Selection field is a field in the record. Who knows, in due time ...

    Imb.

    Sunday, November 15, 2015 8:44 PM
  • Hi DB Guy,

    Your workaround is almost perfect, but to place this in the MouseDown event is the solution bij scrolling with mouse and by scrolling bars.

    Hi Peter,

    Glad to hear you're making good progress. Good luck with your project.

    Sunday, November 15, 2015 9:00 PM