Combobox with dictionnary <string, string>

Hello Team!

having some problem with ComboBox and Dictionnary<string, string>

<SfComboBox ID="inputName" TItem="Dictionary<string, string>" TValue="string" DataSource="@Datasource" @bind-Value="@cell.ColumnValue">
<ComboBoxFieldSettings Value="Key" Text="Value"></ComboBoxFieldSettings>
</SfComboBox>

Dictionary<string, string> Datasource = new Dictionary<string, string>();



seem like it only allows List<> type, How can i make it work?

Thanks,
Chimene Nk.

1 Reply

SN Sevvandhi Nagulan Syncfusion Team June 12, 2020 08:03 AM UTC

Hi NKOUAMBIA, 


Greetings from Syncfusion support. 


We have checked the reported requirement. The DataSource property of the Combobox component will support the type of ICollection. The dictionary type will not be supported.  Hence convert the dictionary type to the list and bind the data source. Please refer to the code below, 

<SfComboBox TValue="string" TItem="Countries" ShowClearButton="false" Placeholder="e.g. Australia" Value="comboValue" DataSource="@DataSource"> 
                <ComboBoxFieldSettings Text="Name" Value="Code"></ComboBoxFieldSettings> 
                <ComboBoxEvents TValue="string" Created="onCreated"></ComboBoxEvents> 
            </SfComboBox> 
 
public void onCreated() 
    { 
        DataSource = Country.Select(p => new Countries { Name = p.Value, Code = p.Key }).ToList(); 
    } 
 
    Dictionary<string, string> Country = new Dictionary<string, string>() { 
        { "1", "Australia"}, 
        { "2", "Bermuda" } 
    }; 



Regards, 
Sevvandhi N 


Loader.
Up arrow icon