Search Unity

Resolved Listview in Listview (multi Listview) (in 2022.2 the problem disappeared)

Discussion in 'UI Toolkit' started by Paulsams, Oct 27, 2021.

  1. Paulsams

    Paulsams

    Joined:
    Feb 14, 2020
    Posts:
    6
    Hello everyone! And someone solved such a problem that I want to allow reorderable inside a Listview, which is an element of another Listview (in makeitem I create an empty Visual Element and put some data into it and additionally put a new Listview), but it is always taking the element of the top Listview, not the inner one. Of course, it happens to me that at the very first creation, I can still move the internal ones without affecting the external ones, but if this is not done in the first element or move the upper list, then everything breaks down.
     
  2. martinpa_unity

    martinpa_unity

    Unity Technologies

    Joined:
    Oct 18, 2017
    Posts:
    480
    Hi! I'm sorry, I don't clearly understand the issue you are mentioning. Can you post some code and maybe a gif of the faulty behaviour to help me understand?
    Thanks!
     
  3. Paulsams

    Paulsams

    Joined:
    Feb 14, 2020
    Posts:
    6
    Here is the code:
    Code (CSharp):
    1. List<VisualElement> items = new(arraySize);
    2.  
    3. for (int i = 0; i < arraySize; ++i)
    4. {
    5.     items.Add(new VisualElement());
    6.     NextToManagedReference(property, items[i], countDigits + 2, 0, ref isEnded);
    7. }
    8.  
    9. Func<VisualElement> makeItem = () => new VisualElement();
    10. Action<VisualElement, int> bindItem = (visualElement, i) =>
    11. {
    12.     visualElement.Add(items[i]);
    13. };
    14. var listView = new ListView()
    15. {
    16.     itemsSource = items,
    17.     makeItem = makeItem,
    18.     bindItem = bindItem,
    19. };
    20. listView.itemIndexChanged += (oldIndex, newIndex) =>
    21. {
    22.     listView.Rebuild();
    23. };
    24. listView.itemsAdded += (items) =>
    25. {
    26.     //add
    27.     listView.Rebuild();
    28. };
    29. listView.itemsRemoved += (indexes) =>
    30. {
    31.     //remove
    32. };
    33.  
    34. listView.reorderable = true;
    35. listView.reorderMode = ListViewReorderMode.Animated;
    36. listView.showFoldoutHeader = true;
    37. listView.headerTitle = nameArray;
    38.  
    39. listView.showAddRemoveFooter = true;
    40. listView.showAlternatingRowBackgrounds = AlternatingRowBackground.All;
    41. listView.showBorder = true;
    42.  
    43. listView.virtualizationMethod = CollectionVirtualizationMethod.DynamicHeight;
    44. listView.showBoundCollectionSize = false;
    45. listView.selectionType = SelectionType.Single;
    46. listView.showAddRemoveFooter = true;
    47.  
    48. builderWeaponWindow.Add(listView);

    This code is for testing purposes only and it doesn't matter what I draw there in NextToManagedReference. I'll just add that it all works through recursion. I call Rebuild so that the height of the elements is calculated normally (and if I comment out their calls, then nothing will change).

    No, if you developed a ListView and took into account that they should work when they are inside each other, then it means that I am doing something wrong.

    Here's a gif of how it all works:
     

    Attached Files: