Welcome to the Blazor feedback portal. We’re happy you’re here! If you have feedback on how to improve the Blazor, we’d love to hear it!

  • Check out the features or bugs others have reported and vote on your favorites. Feedback will be prioritized based on popularity.
  • If you have feedback that’s not listed yet, submit your own.

Thanks for joining our community and helping improve Syncfusion products!

2
Votes

Hi,

I'm having issues trying to add items dynamically into a ListBox. Looking at your example here: https://ej2.syncfusion.com/blazor/documentation/listbox/how-to/add-items/

Note: seems to be outdated, the EjsListBox its generic and the AddItems method its async now.

Here is the Control's code:

<EjsListBox @ref="ListBoxObj"
TValue="string[]"
DataSource="@models"
ModelType="@typeof(Model)"
AllowDragAndDrop="true">
<ListBoxFieldSettings Text="Text" Value="ID" />
<ListBoxEvents TValue="string[]" />
<ListBoxTemplates>
<ItemTemplate>
[...]
</ItemTemplate>
</ListBoxTemplates>
</EjsListBox>

@code {
     EjsListBox<string[]> ListBoxObj;

     private async Task OnClick([...])
     {
          [...]

          // attempt #1
          await ListBoxObj.AddItems(new Model {});

          // attempt #2
          await ListBoxObj.AddItems(new List<Model> { new Model {} });

          [...]
     }
}

Here is the model's class:

public class Model
{
     public int ID { get; set; }
     public string Text { get; set; }
}

I'm expecting (per the documentation) the new item to be added at the end of the list. But instead, the first time I try, nothing happens if I try a second time the list gets cleared and only the new item appears. Also worth to mention that i tried using both approaches (attempt 1/2 in the code above) with the same results.

Help?

Thanks