0
votes

When I click the first item in a multi-select listbox the first click triggers the clicked item as well as items around it.

Many selected
enter image description here

I dug into why and added code to listen to the listbox selection changed event, adding only the selection changed listener and no code made it go away.

Private Sub AllListBox_SelectedIndexChanged

It comes back every so often. Maybe it has to do with the multiselect.

The values are added programmatically by looping through every header on the page and adding it as the value.

Dim InList As Boolean
For Each col In Range(DataRangeBox.Value).Cells
    'Find the row with the headers on it
    If col.row = Range(DataRangeBox.Value).Cells(1).row Then
        'Add item to all available list box
        If IsNull(AllListBox) Then
            AllListBox.AddItem col.Text
        End If
    End If
Next col

Is it similar to the problem discussed here. Will adding the index explicitly solve the problem?

One selected now
enter image description here

2
Is listbox on form or a sheet?S Meaden
The list box is on a formCompyKelly

2 Answers

0
votes

Solved my problem.

On the listbox properties there is the attribute "Multiselect" and I noticed that it was on "fmMultiSelectSingle" when I was getting the problem. I knew I put it on "MultiSelectExtended" as its setting when I created it. So I played with it and once I had it on the one I wanted, I didn't see the problem. I could also reliably reproduce it by making it "fmMultiSelectSingle".

0
votes

I'm having the same problem described: Usually, the first time (only) clicking an item in a listbox, I see 4 items selected (one clicked and 3 below it). For me, the listbox's Multiselect property is properly set to MultiSelectExtended so not what was described above. I've confirmed no code is setting the listbox property otherwise and I've tried manually changing the property to Single and then back to Extended but the problem persists.

I have my problematic listbox on a tab. After opening form/screen, user works in one tab before clicking on this other tab. (When going to this tab with listbox, some brief code runs.)

MY SOLUTION: Today, I decided to add code to use SetFocus for the listbox after user clicks on that tab (at the end of the brief code that currently runs). So focus is on the listobx before I click any item in the list for the first time. This fixed my multiselect issue! Now, only the item clicked in list is selected, correctly.

I hope this idea helps someone else experiencing this quirky problem.