Passing Complex Types on ValueChanged Event For Telerik Blazlor Combo.

1 Answer 69 Views
ComboBox
BL360
Top achievements
Rank 1
BL360 asked on 19 May 2022, 03:45 AM
ValueChanged Event for Complex Types are not firing. Code example as below



@using Telerik.Blazor.Components;
<h1>Hello, Telerik REPL for Blazor! @selectedCodeBase.ItemName </h1>
             
<TelerikComboBox Data="@myComboData" 
    TextField="ItemName" 
    ValueField="ItemKey" 
    TValue="MyDataModel" 
    TItem="MyDataModel"
    ValueChanged="(MyDataModel  s)=>sValueChanged(s)"    
>
</TelerikComboBox>

@code {
public class MyDataModel{
    public string ItemName {get;set;}
    public long ItemKey {get;set;}
}
IEnumerable<MyDataModel> myComboData = Enumerable.Range(1, 20)
       .Select(x => new MyDataModel { ItemName = "item " + x, ItemKey = x });
       

    private MyDataModel selectedCodeBase = new MyDataModel();

 private async void sValueChanged(MyDataModel s)
    {
        await Task.CompletedTask;
    }


}
REPL Example

https://blazorrepl.telerik.com/cmuJFNan441IMFgm37


Please Help.

Thank you

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 22 May 2022, 08:53 AM

Hello,

You can see the supported types of the Value parameter in the documentation: https://docs.telerik.com/blazor-ui/components/combobox/overview#parameters

You can also see how to bind the combo box to a complex type in the following article (key point - the ValueField must be of the primitive type that is supported by Value): https://docs.telerik.com/blazor-ui/components/combobox/data-bind

If you want to get the full model based on selection, you need to extract if from the data source based on the identifier you get in the Value (for more details, see the green note in the article above, this article has a direct example: https://docs.telerik.com/blazor-ui/knowledge-base/dropdowns-get-model).

 

Regards,
Marin Bratanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
ComboBox
Asked by
BL360
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or