Programmatically expand/collapse ListView

Hello! I’m using ListView for writing inspectors and tools and I noticed usually the first time ever I open the inspector/window, the ListViews will be collapsed. I want to be able to programmatically (or through UXML) expand some of them - is that possible?

Thanks in advance!

If you have the SerializedProperty for the list in hand through a custom property drawer that is using editor bindings, you can set its isExpanded property to true. The PropertyField that spawned the list will update it accordingly.

If you have the inspector UI in hand and a reference to the list view, but you’re not using editor bindings, you can query its Foldout and set its value to true. You can use the UI Debugger to get the correct naming or class name for your query if it’s not precise enough, but usually from a ListView reference, listView.Q<Foldout>() works

Hope that helps!

That solved it for me! I don’t have a custom property drawer in this case.
Thanks for the thorough and prompt reply :smile: