Binding data to ListView

You don’t add the widgets to the list directly, instead you create an Object blueprint which will contain the data you want. And when adding an item to the list you construct that object and add it. For it to use your widget, set the Entry Widget Class, to your widget, in the details panel of the List View

So, make a new Blueprint class, pick Object as its parent class (not Actor). In this class add all the variables you need. Set them as Editable and Exposed On Spawn:

264048-lv1.jpg

Then, in your widget which will be the entry, make sure you have implemented the User Object List Entry interface. In the event graph, right click and find the “Event On List Item Object Set”. The object passed in this event is the one you created above, but you’ll need to cast it to your class first to access the variables. You can then use those variables to set the text in your widget or whatever you want to do with the data. Like this for example:

And finally, to actually add entries you use Construct Object, construct an object of the the same class you created above, here you can plug in whatever values you want, and then use Add Item to add it your list. The List handles creating the widgets themselves, it just needs the data.

You could probably iterate through your inventory items and construct add the data objects like I did here:

I’m using tile view but it’s the same idea. I have found the selection bit of tile views are a bit buggy though, at least in 4.21.

5 Likes