ListView

as seeing in the picture, my code is below:
const int itemNum = 5;
var items = new List(itemNum);
for(int i = 0; i < itemNum; ++i)
{
items.Add(i.ToString());
}
var uiDoc = GetComponent<UnityEngine.UIElements.UIDocument>();
var rootElement = uiDoc.rootVisualElement;
var listView = rootElement.Q(“List_server”) as UnityEngine.UIElements.ListView;
listView.makeItem = () => new Label();
Action<VisualElement, int> bindItem = (e, i) => (e as Label).text = items*;*
listView.bindItem = bindItem;
listView.itemsSource = items;
when scolling listview that bug thrown ArgumentOutOfRangeException: Index was out of range

8437967--1118012--8BA4CC7B-A261-44b6-93CC-7744BFC82DEF.png

Hi,

Using your code I had a error on this line:
Action<VisualElement, int> bindItem = (e, i) => (e as Label).text = items*;*

Changing it to:
Action<VisualElement, int> bindItem = (e, i) => (e as Label).text = items*;*
Which makes it compile, I’m not able to reproduce your ArgumentOutOfRangeException issue.

sorry codes is, i donot known why:
Action<VisualElement, int> bindItem = (e, i) => (e as Label).text = items;
but also had that bug.And function bindItem triggled, when scrolling, items were all visible in listview, i thought that function should not triggled,i donot known why that happened.