Problem Setting DataSource on DropDownListModel with string[]

I cannot get the DropDownEdit to bind to a list of simple array strings.  Every time I set the Datasource property I get an exception(see below).   Grid will not go into edit mode and no dropdown.   What am I doing wrong?  I am using SyncFusion.Blazor 19.1.0.59

   `
GridColumn Field="@nameof(ClientViewModel.Status)" EditType="EditType.DropDownEdit" EditorSettings="@StatusEditParams"  HeaderText="Status"
 
Note I have removed the outer tags because it wouldn't show up in this post.
`

@code {

  public List GridData { get; set; }
'

' public static string[] LocalData2 =
    {
        "Prospect",
        "Active",
        "Internal",
        "Supplier",
        "Inactive"
    };

 public IEditorSettings StatusEditParams = new DropDownEditCellParams()
    {
        Params = new DropDownListModel() {DataSource = LocalData2}
    };
}

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Unable to set property 'DataSource' on object of type 'Syncfusion.Blazor.DropDowns.SfDropDownList`2[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[ActivityLog.Shared.ViewModels.ClientViewModel, ActivityLog.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]'. The error was: Specified cast is not valid.
System.InvalidOperationException: Unable to set property 'DataSource' on object of type 'Syncfusion.Blazor.DropDowns.SfDropDownList`2[[System.String, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[ActivityLog.Shared.ViewModels.ClientViewModel, ActivityLog.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]'. The error was: Specified cast is not valid.
 ---> System.InvalidCastException: Specified cast is not valid.
   at Microsoft.AspNetCore.Components.Reflection.PropertySetter.CallPropertySetter[SfDropDownList`2,IEnumerable`1](Action`2 setter, Object target, Object value)
   at Microsoft.AspNetCore.Components.Reflection.PropertySetter.SetValue(Object target, Object value)
   at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.g__SetProperty|2_0(Object target, PropertySetter writer, String parameterName, Object value)
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.g__SetProperty|2_0(Object target, PropertySetter writer, String parameterName, Object value)
   at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.SetProperties(ParameterView& parameters, Object target)
   at Microsoft.AspNetCore.Components.ParameterView.SetParameterProperties(Object target)
   at Syncfusion.Blazor.SfDataBoundComponent.SetParametersAsync(ParameterView parameters)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.SetDirectParameters(ParameterView parameters)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(DiffContext& diffContext, Int32 frameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(DiffContext& diffContext, Int32 frameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange`1 oldTree, ArrayRange`1 newTree)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()

1 Reply 1 reply marked as answer

JP Jeevakanth Palaniappan Syncfusion Team May 7, 2021 06:00 AM UTC

Hi Mark, 

Greetings from Syncfusion support. 

We have analyzed the reported problem and we would like to let you know that the type of Datasource for the default dropdown edit must be same as the type of DataGrid datasource. This should not be a List<string> or string[]. Please refer the below code snippet and the below documentation for your reference. 

<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" EditType="EditType.DropDownEdit" EditorSettings="@CustomerIDEditParams" Width="120"></GridColumn> 
 
@code{ 
 
public static List<Order> LocalData = new List<Order> { 
                new Order() { CustomerID= "United States" }, 
                new Order() { CustomerID= "Australia" }, 
                new Order() { CustomerID= "India" } 
    }; 
} 


If you want to use simple list of string as datasource for dropdownlist control. Kindly refer our UG documentation on EditTemplate to render the DropDownList as custom edit component.  
   

Please get back to us if you have further queries.  

Regards, 
Jeevakanth SP. 



Marked as answer
Loader.
Up arrow icon