Not able to select item

Good night,
I'm begining using comboBox and I'm not able to select an item. If I click in the item, the text stays empty. I'm using an Enum for the value. I'm sending my code bellow.

@using Syncfusion.Blazor.DropDowns

<div class="col-sm-12 col-md-12 col-lg-2">
                <SfComboBox PopupHeight="230px" Placeholder="Tipo Pessoa" TValue="TipoPessoa" TItem="TipoPessoaModel" @bind-Value="@tipoSelecionado" DataSource="@tiposPessoa">
                    <ComboBoxFieldSettings Text="Descricao" Value="Tipo"></ComboBoxFieldSettings>
                </SfComboBox>
            </div>

@code{

    public class TipoPessoaModel
    {
        public TipoPessoa Tipo { get; set; }
        public string Descricao { get; set; }
    }

    public enum TipoPessoa
    {
        Juridica = 0,
        Fisica = 1
    }

    public TipoPessoa tipoSelecionado;
    List<TipoPessoaModel> tiposPessoa = new List<TipoPessoaModel>
    {
        new TipoPessoaModel{Tipo = TipoPessoa.Juridica, Descricao = "Jurídica"},
        new TipoPessoaModel{Tipo = TipoPessoa.Fisica, Descricao = "Física"},
    };
}

5 Replies

BC Berly Christopher Syncfusion Team March 27, 2020 12:50 PM UTC

Hi Társis, 

Greetings from Syncfusion support.  

While checked the provided code example, you have bound the Enum class for TValue in the  Combobox component. In this case, the provided value’s key pair in the Enum class will be set to the component as integer through data source.  

At that time of selecting the value from the popup, actual value integer will not be converted to the TValue type and script error will be thrown. So, the selected value not set to the component and displayed empty text in the input element.  

Hence, we suggest you to set the int? for the TValue and convert the value in the data source as int? as mentioned in the below code example since you have defined the integer values in the Enum class.  

<div class="col-sm-12 col-md-12 col-lg-2"> 
    <SfComboBox PopupHeight="230px" Placeholder="Tipo Pessoa" TValue="int?" @bind-Value="@tipoSelecionado" TItem="TipoPessoaModel" DataSource="@tiposPessoa"> 
        <ComboBoxFieldSettings Text="Descricao" Value="Tipo"></ComboBoxFieldSettings> 
    </SfComboBox> 
</div> 
 
@code{ 
 
    public class TipoPessoaModel 
    { 
        public int? Tipo { get; set; } 
        public string Descricao { getset; } 
    } 
 
    public enum TipoPessoa 
    { 
        Juridica = 0, 
        Fisica = 1 
    } 
    public inttipoSelecionado; 
    List<TipoPessoaModeltiposPessoa = new List<TipoPessoaModel> 
    { 
        new TipoPessoaModel{Tipo = (int)TipoPessoa.JuridicaDescricao = "Jurídica"}, 
        new TipoPessoaModel{Tipo = (int)TipoPessoa.FisicaDescricao = "Física"}, 
    }; 
} 
 
Please find the sample with modified code from the below link. 
 

Regards, 
Berly B.C


Társis March 27, 2020 03:49 PM UTC

Thank you for your answer. It worked. So, actually it won't work with Enums, correct?


BC Berly Christopher Syncfusion Team March 30, 2020 12:45 PM UTC

Hi Társis, 

We would like to inform you that, if we binding the ENUM values with object types in the list instead of assign it directly, we need to convert it based on the provided value’s type in the value filed and assign to the component. So, we suggest you to bind the ENUM values directly like string array as mentioned in the below  
documentation to work it out correctly. 


Regards, 
Berly B.C


JD Jan De Wilde June 16, 2020 07:31 AM UTC

Hi 

I would like to bind to an Enum. I copied the example stated here:

But this doesn't work. I get the folowing error:
Cannot convert from 'string[]' to 'System.Collections.Generic.IEnumerable<Values>'

Are enums still supported?
Thanks


BC Berly Christopher Syncfusion Team June 17, 2020 10:31 AM UTC

Hi Jan, 
  
Sorry for the inconvenience caused. 
  
We would like to inform you that ENUM values are supported in the DropDownList. So, we have created the sample with modified code based on the documentation and attached it below. 
  
  
@using Syncfusion.Blazor.DropDowns; 
 
<SfDropDownList TValue="Values" TItem="string" Placeholder="e.g. Australia" DataSource="@EnumValues" @bind-Value="@ddlVal"> 
</SfDropDownList> 
 
@code{ 
 
    public IEnumerable<string> EnumValues = Enum.GetNames(typeof(Values)); 
    public Values ddlVal { get; set; } = Values.Canada; 
 
    public enum Values 
    { 
        Australia, 
        Bermuda, 
        Canada, 
        Denmark, 
        India, 
        US 
 
    } 
} 
 
  
Also, we will correct the documentation with working code and refresh in the online soon. 
  
Regards, 
Berly B.C 


Loader.
Up arrow icon