How to create an OnGenerateWidget function properly?

Hello everyone

I was trying to create a Combo Box with slate, but I got some errors when I add the function “,OnGenerateWidget”.

This is my function code

TSharedRef<ITableRow> SOptionsWidget::GenerateWidget(TSharedPtr<FIntPoint> Item, const TSharedRef<STableViewBase>& OwnerTable)
{
	if (!Item.IsValid())
	{
		return SNew(SComboRow<TSharedPtr<FIntPoint>>, OwnerTable).Content()
		[
			SNew(STextBlock)
			.Text(FText::FromString("Error"))
		];
	}
	return SNew(SComboRow<TSharedPtr<FIntPoint>>, OwnerTable).Content()
	[
		SNew(STextBlock)
		.Text(FText::Format(FText::FromString("{0}x{1}"), FText::FromString(FString::FromInt(Item->X)), FText::FromString(FString::FromInt(Item->Y))))
		.ColorAndOpacity(FColor::Black)
	];
}

And I got this error

Error 1	error C2664: 'SComboBox<TSharedPtr<FIntPoint,0>>::FArguments &SComboBox<TSharedPtr<FIntPoint,0>>::FArguments::OnGenerateWidget(const TBaseDelegate<TSharedRef<SWidget,0>,ArgumentType> &)' : cannot convert argument 2 from 'TSharedRef<ITableRow,0> (__cdecl SOptionsWidget::* )(TSharedPtr<FIntPoint,0>,const TSharedRef<STableViewBase,0> &)' to 'TSharedRef<SWidget,0> (__cdecl SOptionsWidget::* )(ArgumentType)' C:\Users\Samuel\Documents\Unreal Projects\Project2DCpp\Source\Project2DCpp\Private\SOptionsWidget.cpp	60	1	Project2DCpp

4 IntelliSense: no instance of overloaded function "SComboBox<OptionType>::FArguments::OnGenerateWidget [with OptionType=TSharedPtr<FIntPoint, ESPMode::NotThreadSafe>]" matches the argument list
   argument types are: (SOptionsWidget *, TSharedRef<ITableRow, ESPMode::NotThreadSafe> (SOptionsWidget::*)(TSharedPtr<FIntPoint, ESPMode::NotThreadSafe> Item, const TSharedRef<STableViewBase, ESPMode::NotThreadSafe> &OwnerTable))
            object type is: SComboBox<TSharedPtr<FIntPoint, ESPMode::NotThreadSafe>>::FArguments	c:\Users\Samuel\Documents\Unreal Projects\Project2DCpp\Source\Project2DCpp\Private\SOptionsWidget.cpp	60	7	Project2DCpp

The line 60 is: “.OnGenerateWidget(this, &SOptionsWidget::GenerateWidget)”

How can I get this working properly?

Sorry for my English

Thanks!

Can anyone help me?

You appear to be trying to bind this method to a SComboBox< TSharedPtr< FString > >, but your method item type is TSharedPtr< FIntPoint >. The item type needs to be the same.

My mistake, I was using “FString” before, but now I’m using “FIntPoint” and I forgot to change, but the error still the same.

I edited the post with the updated error.

Your GenerateWidget function should return shared reference to SWidget, not reference to ITableRow.

So it should look like this:

 TSharedRef<SWidget> SOptionsWidget::GenerateWidget(TSharedPtr<FIntPoint> Item)
    {
  return  SNew(STextBlock)
         .Text(FText::Format(FText::FromString("{0}x{1}"), FText::FromString(FString::FromInt(Item->X)), FText::FromString(FString::FromInt(Item->Y))))
         .ColorAndOpacity(FColor::Black);
    }

It worked.

Thanks!