How to Add Item widget to ListView or Vertical Box at runtime?

Need to make scrollable list of same class widgets at runtime. Tried 3 ways:

  1. Make ListView in Designer → Add new item at runtime
    problem - nothing on screen

  1. Make ListView in Designer → Create new item at runtime and give List view reference as parameter
    problem - widget appear, but not in list view.
  2. Make Vertical Box and use method like in video - problem - VerticalBox dosen’t in variables tab, so I can’t get reference to it to add widget.
    [link text][1]

Thank you! It helps!

Hello MasterOfDreams,

it is a better practice to encapsulate functionality to their respective class, that said,
I can give you an example how you’d be able to make it work, bear in mind though that this is quite possibly not the best solution, but it will work.

Here you can see what I did in the widget blueprint:

The ‘AddListItem’ event is a custom event I created.

I went for a separate widget blueprint as a preset for the list item, which is a class reference; because you want to create instances of said widget.

296017-variable-type.png

And if you want to reference widgets from the designer, you just have to set the ‘Is Variable’ flag in the designer detail panel, with the widget selected you want to make a variable of:

296018-convert-widget-to-variable.png

I parented the vertical box to a scroll view, and that’s all you need for the widget blueprint so far.

And lastly here is what I did in the player. At first I created a widget instance of type of the widget holding the list, and if you want to add a list item to the list you just have to call the event of the widget. Here I chose the space bar down event but you can plug in what ever you want.

If you want to create a list item with a certain content, you can just expose an event inside the list item widget blueprint to set the content at the point of creation, you then can add all necessary inputs to the ‘AddListItem’ event to control the list item creation.

Hope that helps. If you’re in need of further assistance, just let me know.

Regards,

Vecherka.

Hello MasterOfDreams,

good to know :),

if this answered your question, don’t forget to mark this question as answered so it’s easier for others with the same problem to find this thread.