Am unable to figure out this issue with ListView and UserObjectListEntry [C++]

Initially I have a ListView Widget and also A item which inherits from UserObjectListEntry as it is mandatory.

Creating item and displaying data of item is working properly at beginning but,

What I Am Trying to do is:

There are a few bind widgets in my item, and i want to change data of those widgets on runtime.

Lets say I want to change text of UTextBlock on some button click on other method.

What I tried:

I have tried directly accessing the pointer to bind widget and changing. In debug message it is changing but on screen UI value is not changing.

I have tried adding same pointer to a TArray on creating of item , and accessing bind widget, ofc it is same whether through TArray or directly, but yeah i did tried it just to be sure.

What I want:

I want to change UTextBlock->SetText() after already adding item to ListView.

Alternative that are in my mind:

Maybe I could remove the item i want to update and create again with the updated data . But I dont think it will be an ideal solution. Hopefully i get help from other experts before I choose this last workaround solution.

Am not a highly professional Unreal Dev, I appreciate polite and detailed responses.

To change the text of a UTextBlock widget in a ListView widget after the item has been added, you can use the SetText method of the UTextBlock widget.

Here’s an example of how you can do this:

  1. Get a reference to the UTextBlock widget in your item class:
UPROPERTY(EditAnywhere, Category = "Widgets")
    UTextBlock* TextBlock;
  1. In your OnListItemObjectSet function, get a reference to the UTextBlock widget and change its text:
void IMyListView::OnListItemObjectSet(IUserObjectListEntry* NewEntry, IUserObjectListEntry* OldEntry)
{
    if (OldEntry && OldEntry->GetWidget() && OldEntry->GetWidget()->GetClass() == UTextBlock::StaticClass())
    {
        UTextBlock* TextBlock = static_cast<UTextBlock*>(OldEntry->GetWidget());
        TextBlock->SetText("New Text");
    }
}

This will change the text of the UTextBlock widget in the old entry to “New Text”.

Note that you need to make sure that the UTextBlock widget is properly initialized and has a valid pointer to the UTextBlock class before calling the SetText method.

Where should i call OnListItemObjectSet(args)?
I suppose it is called automatically, i mean am not getting the point. i want to update text on button click of some other actor component.

am really sorry if am not getting what you are trying to convey.

You should call OnListItemObjectSet(args) in the ListView widget’s implementation. This function is called whenever a new item is added to the list or an existing item’s properties change. In this case, you want to change the text of a UTextBlock widget in the list, so you should call OnListItemObjectSet(args) in the ListView widget’s implementation.

whatever you are saying “This function is called whenever a new item is added to the list or an existing item’s properties change”.

but that functionality is already being handled by overridden method OnListItemObjectSet(args)

Edit:
on creating item, am already assigning values, but i want to change that existing data on gameplay at any time of player’s need.

The OnListItemObjectSet function is called automatically by the ListView widget when a new item is added to the list or an existing item is replaced. It is not called on button click of another actor component.

If you want to update the text of a UTextBlock widget in a ListView widget on button click of another actor component, you can add an event listener to the button component that calls the SetText method of the UTextBlock widget.

Here’s an example of how you can do this:

  1. Add an event listener to the button component that calls the SetText method of the UTextBlock widget:
UPROPERTY(EditAnywhere, Category = "Widgets")
UTextBlock* TextBlock;

void MyButtonComponent::OnButtonClicked()
{
    if (TextBlock)
    {
        TextBlock->SetText("New Text");
    }
}
  1. In your ListView widget, make sure that the UTextBlock widget is properly initialized and has a valid pointer to the UTextBlock class.

Okay so , of what i understood is whenever is call function UTextBlock->SetText(), OnListItemObjectSet is called which have args of old and new entries, and i should get old entry’s text value and sent that to new entry?

Edit:

just a quick question, we are setting text again in OnListItemObjectSet() wont it call the OnListItemObjectSet() again to loop?

Yes, that is correct. Whenever you call the SetText() method of a UTextBlock widget, the OnListItemObjectSet() function of the ListView widget will be called. This function is called automatically by the ListView widget whenever a new item is added to the list or an existing item is replaced.

If you want to update the text of a UTextBlock widget in a ListView widget on button click of another actor component, you can add an event listener to the button component that calls the SetText() method of the UTextBlock widget.

Here’s an example of how you can do this:

  1. In your ListView widget, make sure that the UTextBlock widget is properly initialized and has a valid pointer to the UTextBlock class.
  2. Add an event listener to the button component that calls the SetText() method of the UTextBlock widget.
  3. In the OnButtonClicked() function of the button component, get the text value of the old entry and set the text value of the new entry to it.

Here’s an example of how you can implement this:

UPROPERTY(EditAnywhere, Category = "Widgets")
UTextBlock* TextBlock;

void MyButtonComponent::OnButtonClicked()
{
    if (TextBlock)
    {
        // Get the text value of the old entry
        FString OldText = TextBlock->GetText();

        // Set the text value of the new entry to the old text value
        TextBlock->SetText(OldText);
    }
}

Note that calling the SetText() method of the UTextBlock widget will not cause the OnListItemObjectSet() function to be called again, as this function is called automatically by the ListView widget whenever a new item is added to the list or an existing item is replaced.

understood, if you dont mind, can i just know what goes in method OnListItemObjectSet() so that i will be able to change old text to new text?

The OnListItemObjectSet() function is called automatically by the ListView widget whenever a new item is added to the list or an existing item is replaced. It is not called when you call the SetText() method of a UTextBlock widget directly.

To change the text of a UTextBlock widget in a ListView widget on button click of another actor component, you can add an event listener to the button component that calls the SetText() method of the UTextBlock widget.

Here’s an example of how you can do this:

  1. In your ListView widget, make sure that the UTextBlock widget is properly initialized and has a valid pointer to the UTextBlock class.
  2. Add an event listener to the button component that calls the SetText() method of the UTextBlock widget.
  3. In the OnButtonClicked() function of the button component, get the text value of the old entry and set the text value of the new entry to it.

Here’s an example of how you can implement this:

UPROPERTY(EditAnywhere, Category = "Widgets")
UTextBlock* TextBlock;

void MyButtonComponent::OnButtonClicked()
{
    if (TextBlock)
    {
        // Get the text value of the old entry
        FString OldText = TextBlock->GetText();

        // Set the text value of the new entry to the old text value
        TextBlock->SetText(OldText);
    }
}

Note that calling the SetText() method of the UTextBlock widget will not cause the OnListItemObjectSet() function to be called again, as this function is called automatically by the ListView widget whenever a new item is added to the list or an existing item is replaced.

Hey man, it is not working. i have debug log OnListItemObjectSet() , it is not even triggering.
also the method args you mentioned are not matching what it is showing here in visual studio.
here is it …

void UMyItemClass::OnListItemObjectSet(UObject* ListItemObject)
{
    UE_LOG(LogTemp, Display, TEXT("OnListItemObjectSet Called"));
}

Don’t fall for the chatgpt nonsense.

It is a bit unclear what you tried to do and what failed.
If I get this right, you have a list item widget based on a C++ class which relies on BindWidget to reference a text block.
You want to change the text block upon pressing a button. Where is the button ? Is it also part of the list item widget ? Or is it part of a different widget ?
If it’s a different widget, how do you know which list entry to modify ?