ListView dynamic update

Friends! Tell me why, when you try to update the text in the list, an error occurs . I created a project on github.

I guess I don’t know anything. Really need help.

After starting the project, there will be a button on the screen. When you click on the button, a list with the text in each line should appear. The text is put in C++.

But instead, a list with the initial text set to BP appears and an error falls out.

I tried to understand and it turns out that the list item is not created at the time of installation of the text. But for what reason remains a mystery to me.

Look please, if not difficult, where there is a mistake.

Error occurs when calling the method
void UListComponent_CPP::SetActionName(FString TaskName)

and it happens because there is ensureMsgf(…).
But if you disable ensureMsgf, the Studio falls.

It crashes because the TextBlock_ActionName pointer is undefined. And very strange!!! For me:)

If the method implementation
void UListComponent_CPP::SetActionName(FString TaskName)

move to the constructor - set the text in the constructor, then there is no error and everything works well.

Please explain where am I wrong?

you not created instance of TextBlock_ActionName.

execute this code an UListComponent_CPP class function.

TextBlock_ActionName = WidgetTree->ConstructWidget(UTextBlock::StaticClass(), “example”);

Frend! The instance TextBlock_ActionName is created by this line UPROPERTY(BlueprintReadWrite, meta = (BindWidget))

I did not know how. Thank you very much.

The list view item is generated when it enters the drawing area by scrolling or the like.

You must bind “OnEntryGenerated” or implement UListView by inheriting “UListView :: OnGenerateEntryWidgetInternal ()”.

Have you tried cloning a project and doing what offers? :slight_smile:

i am sc-stsubasa.from private account

I’m sorry. I was thinking too hard.
Please try the changes below.

class UListComponent_CPP
  //	add
  FText MyTaskName;
void UListComponent_CPP::NativeConstruct()

  // add

void UListComponent_CPP::SetActionName(FString TaskName)

#if true
    MyTaskName = FText::FromString(TaskName);
  if (ensureMsgf(TextBlock_ActionName, TEXT("TextBlock_ActionName is invalid")))



My answer hasn’t changed - Have you tried cloning a project and doing what offers? :)))

I copied your project and confirmed it.

Excuse me, do you understand that the time when the list view item is generated as a widget and NativeConstruct is called is when it enters the display area?

Oh, my friend, forgive me. Maybe you can solve this problem then. Could you then make a push of code with a working example? The thing is that I tried to update the text in the list at different times of widget generation and yet the quest is not completed. :))

I checked a little, but ListView did something strange.

You can see that creating a constructor for UListComponent_CPP and setting a breakpoint
It seems that a completely new UListComponent_CPP is being generated instead of using the one set when entering the area.

※ Confirmed by the following constructor

UListComponent_CPP :: UListComponent_CPP (const FObjectInitializer & ObjectInitializer)
: Super (ObjectInitializer)

The following code is generated

ListViewBase.h (471)
WidgetEntryT & GenerateTypedEntry (TSubclassOf  WidgetClass, const TSharedRef  & OwnerTable);

OnEntryGenerated bound to the blueprint graph only passed the object generated above.
The rough calling order is as follows, so it may be better to look a little.

UListViewBase :: GenerateTypedEntry ()
UListViewBase :: FinishGeneratingEntry ()
UListViewBase :: HandleAnnounceGeneratedEntries ()
UListViewBase :: BP_OnEntryGenerated.Broadcast (EntryWidget.Get ());

The only way to think of it now is to inherit UListView and override OnGenerateEntryWidgetInternal () …

Very strange! A simple task - When you click on the button, update the list item. The update logic must be in C++. Asked this task here, in Discordchats in two channels, sent questions to youtubers who clever lessons do. No answer. Not who does not know how to work with it. Only simple General advice and remark - need to do so and so and so. And when you ask a question - You tried to realize your advice? - going oops…:)) Sorry, mate! Thank you for your help! You held out the longest:))