ListView OnItemSelectionChanged fires multiple times when scrolling

I have implemented a ListView with A list entry item that contains border, image ,and text. I set a single selection and added a blueprint logic that sets selected item’s border color green and unselected grey. I also set the list widget size fixed to allow scrolling. What happens is that when selecting list entries in the visible area it works okay. The selection is always single at the clicked item. But once I begin scrolling up and down, the entries that enter the visible area start firing On Selection Changed events and the selection color appears on multiple items. I verified this behavior by printing the event triggers. The last time I implemented a ListView was in 4.25 and I don’t remember having such a bug.
I tried to handle OnSelectionChanged event both on the ListView level and on the List Item level. It behaves the same. Is it expected behavior of the list view?

1 Like

Hi SasMaster

I think I see two separate issues, I hope I can help with both!

So we are on the same page:

ListView: A list based on around Items, and widgets that are used to visually represent them

Item: An object. Does not know it is an Item. Can be literally any unrelated object you want I believe. e.g. StaticMeshActor, Pawn, Material Instance etc.

Entry: A Widget used to visually represent an Item. Does not know the Item it represents

After one item selected, scrolling makes some new entries appear selected

(I find it very easy to mistake usage of Entry and Item, so I typed them in bold to help with clarity)

On initial construction, a ListView will construct the minimum amount of Entries necessary to fill the visible area of the scroll space. When an Item scrolls out of view it’s Entry widget is “released” not destroyed, then when an Item needs to come into view, one of the released Entry widgets gets re-used to represent it.

So, what could be happening is you click an Item, selecting it, your Entry widget then changes it’s visuals to show this change. You scroll that Item out of view, the Entry widget gets released, then since a new Item is scrolled into view, it gets assigned to represent it. So you have the same Entry widget now representing a different Item further down the list, showing the visuals of it being selected (but the Item itself actually isn’t selected).

What you can use to regulate this is OnEntryInitialized (In the widget that has the ListView). It fires when an Item comes into view (and also items that start off already in view initially).

Your setup could look something like this ^

OnItemSelectionChanged Multiple Firings after 1 selection

I don’t seem to be getting the same behavior here, I find that OnItemSelectionChanged (Entry Widget) only fires when:

-In view and item it represents is selected/unselected

-Assigned to the already selected item (when the selected item scrolls back into view)

OnItemSelectionChanged (List view) Only fires when an Item in view is clicked.

Let me know if you still experience behavior different to this, once solving the other issue with multiple items appearing selected.
Just comment with further details of your code setup and I’ll see what I can do :slight_smile:

Hope this all helps :slight_smile:

4 Likes

Your first part is something worth to check but it seems to me as a workaround to an existing bug. Your second remark - yes it fires multiple times. I verified it with printing the event trigger from within a list entry widget I am using. This is not the first time I am working with the list view widget. It is too complex, buggy and I don’t understand why Epic don’t do something about it. For now I removed the border widget and stopped using highlight effect for selected entry.
PS: regarding your other questions/remarks: I am talking about list view entry widget, not about any data objects it is using to fill the data.

I would expect OnSelectionChanged event to fire only when a user clicked it and not when it enters the visible area or exists it.

Initially I thought the same, but due to the nature of an Entry Widget not knowing when it is assigned to a selected item otherwise, it is handy.

Note: The behavior I experience still the same as my answer, where OnSelectionChanged(EntryWidget) does not fire when a selected item exits the visible area, only when an item is selected/unselected (in visible area), or when a selected item enters visible area.

Firing OnSelectionChanged(EntryWidget) when a selected item enters the visible area provides a quick, and easy way for the widget to identify when it is assigned to a selected item (given the polyamorous relationship an entry widget has with the items in the list).

I will gladly make a small UE4 app with the setup I have here and send you so you can reproduce the same behavior. (maybe I am doing something wrong there,who knows :wink: Please let me know if it’s possible. Thanks.

Yeah I’d be happy to take a look at your project, do you have a github repo or a download link?

OnEntryInitialized hack worked. Thank you very much!

Again just to emphasize, this isn’t a hack, it’s the intended method for setting/resetting details of your entry widgets, based on the item they now represent (because EntryWidgets that leave the view are re-used to represent Items entering view).

1 Like