Download

List View ! Please help me implement It In C++

I do this simple guide here: https://historia.co.jp/archives/10389/ . But that’s all in Blueprint.

https://historia.co.jp/wp/wp-content/uploads/2018/09/blogimg190922I.gif

EntryData (Widget):

https://historia.co.jp/wp/wp-content/uploads/2018/09/blogimg190922F-1024x229.png

Widget has ListView:

https://historia.co.jp/wp/wp-content/uploads/2018/09/blogimg190922H-1024x176.png

*** So, How to implement it in C++
- Event On List Item Object Interface ? Where , How?

Thank you?

Have you tried using UUserWidget class ? Explore a bit, you can create them on runtime and add them to any other widget or directly viewport

Search engine source for “SListView” for examples.

You need a SListView, a shared FString array, and a ITableRow generator method:



TSharedPtr<SListView<TSharedPtr<FString>>> LineCounter;
TArray<TSharedPtr<FString>>LinesText;

TSharedRef<ITableRow>OnGenerateLineCounter( TSharedPtr<FString>Item, const TSharedRef<STableViewBase> & myTable );




TSharedRef<ITableRow>SMyWidget::OnGenerateLineCounter( TSharedPtr<FString>Item, const TSharedRef<STableViewBase> & myTable ) {
   return SNew(SComboRow<TSharedRef<FString>>, myTable)
   
       SNew(SBorder)
      .Padding(FMargin(5.f,0.f,5.f,0.f))
      
         SNew(STextBlock)
         .Text(FText::FromString( *Item.Get() ))
      ]
   ];
}




SAssignNew( LineCounter, SListView<TSharedPtr<FString>> )
   .OnGenerateRow(this, &SMyWidget::OnGenerateLineCounter)
   .ListItemsSource(&LinesText).ItemHeight(14)
   .SelectionMode(ESelectionMode::Single)


2 Likes

Thanks for your advice.


void UItemEntryWidget::NativeOnListItemObjectSet(UObject* ListItemObject)
{
UItemData* Data = Cast<UItemData>(ListItemObject);
ItemName->SetText(FText::FromString(Data->Text));
}



void UInventoryWidget::NativeConstruct()
{
ListViewItem->SetScrollbarVisibility(ESlateVisibility::Hidden);

for (size_t i = 0; i < 5; i++)
{
ItemData = NewObject<UItemData>(this);
ItemData->Text = FString::Printf(TEXT(" Old %d"), i);

ListViewItem->AddItem(ItemData);
}
}

But I execute this:


auto UWidgets = ListViewItem->GetDisplayedEntryWidgets();
UE_LOG(LogTemp, Warning, TEXT("UWidgets Size = %d"), UWidgets.Num());

**Result : 0. **

Maybe: not All EntryWidgets reference when Add Item. Any else help me?

Maybe you could try using bindwidget for displaying and you should use getnumitems to find the listview length.