How to prevent Listview automatically reorder the item views after unfolding?

Hi everyone,

I have a list of items, each item has a different view (VisualElement).
So I bind each item to its own view in ListView.bindItem().
But after I fold and unfold it using Foldout, the ListView automatically reorders the item views.
Then it calls bindItem() and the the view (VisualElement) corresponding to the item index has been changed.
I cannot rebind them because each item has its own view and the item view doesn’t match the item index anymore.

Is there any way to prevent it from being reordered after unfolding?
Or I have to rebuild the ListView after unfolding it?

I’m using Unity 2023.2.

I may miss something, but It is expected that the ListView will rebind the elements at will: it is a virtualized list and will only bind what is displayed, reuse the items when scrolling. That is probably why you are seeing a ListView item being assigned a different index.

If you want to work with the list view, you will need to be able to call the bindItem method on any item at any moment with any index .

What I understand is that you have some unique visual per item/row : do you need the virtualization? a regular scroll view that you populate by had could fit your need otherwise.