SfComboBox throws a null reference exception in OnInitializedASync

I have an SfComboBox throw a null reference exception in OnInitializedASync(), and I cannot figure why. Also, the ValueChange callback never gets called. I have similar code for another SfComboBox (which is not inside a grid) that works.

Here's my code.

HTML

    <SfGrid @ref="palettenGrid" TValue="VersandPalettenInfo" DataSource="@palettenListe" EnableVirtualization="true" EnableVirtualMaskRow="true" AllowSorting="false" AllowFiltering="false" Height="100%">
        <GridEvents TValue="VersandPalettenInfo"
                    OnActionFailure="OnActionFailure"
                    OnLoad="OnLoad"
                    Created="OnCreated"
                    OnToolbarClick="OnToolbarClick"
                    RowSelected="OnRowSelected"
                    CommandClicked="OnCommandClicked"
        />
        <GridPageSettings PageSize="100"></GridPageSettings>
        <GridColumns>
            <GridColumn Field=@nameof(VersandPalettenInfo.Text) HeaderText="Palettentyp" Width="200" EditType="EditType.DropDownEdit" HeaderTextAlign="TextAlign.Center" TextAlign="TextAlign.Center">
                <Template>
                    <SfDropDownList ID="Typ" Placeholder="" TItem="TAB_SPEDITIONSVERSAND" TValue="TAB_SPEDITIONSVERSAND" DataSource="palettenTypen" @bind-Value=@((context as VersandPalettenInfo).Info)>
                        <DropDownListFieldSettings Text="TEXT" Value="TAB_SPEDITIONSVERSAND"></DropDownListFieldSettings>
                        <ComboBoxEvents TItem="TAB_SPEDITIONSVERSAND" TValue="TAB_SPEDITIONSVERSAND" ValueChange="OnSelectPalettenTyp"></ComboBoxEvents>
                    </SfDropDownList>
                </Template>
            </GridColumn>
        </GridColumns>
    </SfGrid>


Data Types

    [Table("TAB_SPEDITIONSVERSAND")]
    public partial class TAB_SPEDITIONSVERSAND
    {
        [Key]
        [StringLength(3)]
        public string PALETTENTYP { get; set; } = "";
        public int LAENGE_CM { get; set; }
        public int BREITE_CM { get; set; }
        public int HOEHE_CM { get; set; }
        [StringLength(2000)]
        public string TEXT { get; set; } = "";
    }

    public class VersandPalettenInfo
    {
        public VersandPalettenInfo()
        {
            Info = new();
        }
        public VersandPalettenInfo(TAB_SPEDITIONSVERSAND i)
        {
            Info = i;
        }
        public TAB_SPEDITIONSVERSAND Info { get; set; }
        public int Anzahl { get; set; } = 1;
        public float Volumen => (float)(Laenge * Breite * Hoehe) / 1e6f;
        public string Typ => Info.PALETTENTYP;
        public int Laenge => Info.LAENGE_CM;
        public int Breite => Info.BREITE_CM;
        public int Hoehe => Info.HOEHE_CM;
        public string Text => Info.TEXT;
    }


Code

    SfGrid<VersandPalettenInfo> palettenGrid;
    public List<TAB_SPEDITIONSVERSAND> palettenTypen = null;
    public TAB_SPEDITIONSVERSAND palettenTyp = new();
    protected ObservableCollection<VersandPalettenInfo> palettenListe = new ObservableCollection<VersandPalettenInfo>();

    public void Setup ()
    {
        if (palettenTypen is null)
        {
            palettenTypen = new();
            foreach (TAB_SPEDITIONSVERSAND p in SpeditionsversandCache.ValuesList)
                palettenTypen.Add(p);
        }
        if (palettenListe.Count > 0)
            palettenListe.Clear();
        palettenListe.Add(new VersandPalettenInfo(palettenTypen [0]));
    }


    private void OnSelectPalettenTyp(Syncfusion.Blazor.DropDowns.ChangeEventArgs<TAB_SPEDITIONSVERSAND, TAB_SPEDITIONSVERSAND> args)
    {
        //DataHandler.Select(args.Value);
        palettenTyp = args.Value;
        StateHasChanged();
    }


Error Message

    crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
          Unhandled exception rendering component: Object reference not set to an instance of an object.
    System.NullReferenceException: Object reference not set to an instance of an object.
       at Syncfusion.Blazor.DropDowns.ComboBoxEvents'2.<OnInitializedAsync>d__68[[StreckerShop.Shared.Stammdaten.TAB_SPEDITIONSVERSAND, StreckerShop.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[StreckerShop.Shared.Stammdaten.TAB_SPEDITIONSVERSAND, StreckerShop.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].MoveNext()'
       at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()



3 Replies

PM Ponmani Murugaiyan Syncfusion Team March 7, 2022 05:37 AM UTC

Hi Dietfrid, 

Based on your shared code snippet, the cause for the issue is you have used the ComboBoxEvents tag inside the DropDownList component. We suggest you to use the same event tag name (DropDownListEvents) inside the DropDownList component as like below code snippet to get rid of the issue. 

<GridColumn Field=@nameof(VersandPalettenInfo.Text) HeaderText="Palettentyp" Width="200" EditType="EditType.DropDownEdit" HeaderTextAlign="TextAlign.Center" TextAlign="TextAlign.Center"> 
    <Template> 
        <SfDropDownList ID="Typ" Placeholder="" TItem="TAB_SPEDITIONSVERSAND" TValue="TAB_SPEDITIONSVERSAND" DataSource="palettenTypen" @bind-Value=@((context as VersandPalettenInfo).Info)> 
            <DropDownListFieldSettings Text="TEXT" Value="TAB_SPEDITIONSVERSAND"></DropDownListFieldSettings> 
            <DropDownListEvents TItem="TAB_SPEDITIONSVERSAND" TValue="TAB_SPEDITIONSVERSAND" ValueChange="OnSelectPalettenTyp"></DropDownListEvents> 
        </SfDropDownList> 
    </Template> 
</GridColumn> 

Regards, 
Ponmani M 



DM Dietfrid Mali March 7, 2022 04:31 PM UTC

Yeah thanks, I managed to figure that myself after long hours last week. If you stare at the same piece of code for too long, you are getting blind spots ...



PM Ponmani Murugaiyan Syncfusion Team March 8, 2022 04:03 AM UTC

Hi Dietfrid, 

Thanks for the update. We are glad to hear that the issue has been resolved. 

Regards. 
Ponmani M 


Loader.
Up arrow icon