Search Unity

Question How to use ListView?

Discussion in 'UI Toolkit' started by D-DutchDave, May 2, 2022.

  1. D-DutchDave

    D-DutchDave

    Joined:
    May 4, 2018
    Posts:
    36
    Hello all,

    I'm working on a tool using UI elements and am stuck at how to utilize the ListView. I'm aiming for it to look similar to how a list would look in your ordinary inspector (in newer versions with the reordering). Does anyone have any examples maybe, or tips as to where to look for a comprehensible piece of documentation?

    Thanks in advance!
     
    MintTree117 likes this.
  2. griendeau_unity

    griendeau_unity

    Unity Technologies

    Joined:
    Aug 25, 2020
    Posts:
    248
    Here are some manual pages on ListView
    ListView API example: https://docs.unity3d.com/ScriptReference/UIElements.ListView.html
    Custom implementation: https://docs.unity3d.com/2022.1/Documentation/Manual/UIE-ListView-TreeView.html
    Using bindings: https://docs.unity3d.com/Manual/UIE-bind-to-list.html
    Other useful links: https://forum.unity.com/threads/whats-new-in-the-ui-toolkit-documentation.1256697/

    Using a PropertyField bound to a list will out of the box use the reorderable look.

    To get it with a manual setup, here are the properties you want to set:
    - `reorderMode` -> ListViewReorderMode.Animated
    - `reorderable` -> true
    - `showAddRemoveFooter` -> true
    - `showFoldoutHeader` -> true (along with `headerTitle`)
     
    MintTree117 likes this.